Skip to content
Snippets Groups Projects
Commit 6a12b807 authored by Jaime Perez Crespo's avatar Jaime Perez Crespo
Browse files

Add a temporary autoloader that allows loading old classes...

Add a temporary autoloader that allows loading old classes (SimpleSAML_Path_Something) that have already migrated to namespaces (SimpleSAML\Path\Something), while logging a warning. This commit requires to regenerate the composer autoloader with ./composer.phar dump-autoload.
parent a44588d7
No related branches found
No related tags found
No related merge requests found
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
} }
], ],
"autoload": { "autoload": {
"psr-0": { "psr-4": {
"SimpleSAML": "lib/" "SimpleSAML\\": "lib/SimpleSAML"
}, },
"files": ["lib/_autoload_modules.php"] "files": ["lib/_autoload_modules.php"]
}, },
......
...@@ -8,5 +8,34 @@ ...@@ -8,5 +8,34 @@
* @package SimpleSAMLphp * @package SimpleSAMLphp
*/ */
/**
* This temporary autoloader allows loading classes with their old-style names (SimpleSAML_Path_Something) even if they
* have been migrated to namespaces, by registering an alias for the new class. If the class has not yet been migrated,
* the autoloader will then try to load it.
*
* @param string $class The full name of the class using underscores to separate the elements of the path, and starting
* with 'SimpleSAML_'.
* @deprecated This function will be removed in SSP 2.0.
*/
function temporaryLoader($class)
{
if (!strstr($class, 'SimpleSAML_')) {
return; // not a valid class name for old classes
}
$path = explode('_', $class);
$new = join('\\', $path);
if (class_exists($new, false)) {
SimpleSAML_Logger::warning("The class '$class' is now using namespaces, please use '$new'.");
class_alias($new, $class);
}
$file = dirname(__FILE__).DIRECTORY_SEPARATOR.join(DIRECTORY_SEPARATOR, $path).'.php';
if (file_exists($file)) {
require_once $file;
}
}
spl_autoload_register("temporaryLoader");
spl_autoload_register(array('SimpleSAML_Module', 'autoloadPSR0')); spl_autoload_register(array('SimpleSAML_Module', 'autoloadPSR0'));
spl_autoload_register(array('SimpleSAML_Module', 'autoloadPSR4')); spl_autoload_register(array('SimpleSAML_Module', 'autoloadPSR4'));
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment