Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Add legacy autoloader to support Matomo namespaces in 3.X (#16069)
- Loading branch information
Showing
with
33 additions
and 1 deletion.
- +31 −0 LegacyAutoloader.php
- +2 −1 composer.json
@@ -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(); |