diff --git a/composer.json b/composer.json index b4c998cd436d6a658816fdc0784d458474c21e35..cc7ed22be5ec5eecc2c6723398ef9c2b31a0ca1c 100644 --- a/composer.json +++ b/composer.json @@ -20,8 +20,8 @@ } ], "autoload": { - "psr-0": { - "SimpleSAML": "lib/" + "psr-4": { + "SimpleSAML\\": "lib/SimpleSAML" }, "files": ["lib/_autoload_modules.php"] }, diff --git a/lib/_autoload_modules.php b/lib/_autoload_modules.php index 62aa262e4c9ca797271871a63ab57c2991ebc5b3..c5524252b364f089f4dd235ce3a9211b609a8fb2 100644 --- a/lib/_autoload_modules.php +++ b/lib/_autoload_modules.php @@ -8,5 +8,34 @@ * @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', 'autoloadPSR4'));