Skip to content

Commit

Permalink
Add legacy autoloader to support Matomo namespaces in 3.X (matomo-org…
Browse files Browse the repository at this point in the history
  • Loading branch information
tsteur authored and jonasgrilleres committed Sep 22, 2020
1 parent 95b71fd commit 7c45f1f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
31 changes: 31 additions & 0 deletions LegacyAutoloader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

class LegacyAutoloader
{
public function __construct()
{
spl_autoload_register(array($this, 'load_class'));
}

public static function register()
{
new LegacyAutoloader();
}

public function load_class($className)
{
if (strpos($className, 'Matomo\\') === 0) {
$newName = 'Piwik' . substr($className, 6);
if (class_exists($newName) && !class_exists($className, false)) {
@class_alias($newName, $className);
}
} elseif (strpos($className, 'Piwik\\') === 0) {
$newName = 'Matomo' . substr($className, 5);
if (class_exists($newName) && !class_exists($className, false)) {
@class_alias($newName, $className);
}
}
}
}

LegacyAutoloader::register();
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@
"HTML_": "libs/",
"PEAR_": "libs/",
"Archive_": "libs/"
}
},
"files": ["LegacyAutoloader.php"]
},
"autoload-dev": {
"psr-4": {
Expand Down

0 comments on commit 7c45f1f

Please sign in to comment.