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

Make the module autoloader to register class aliases for the classes that are...

Make the module autoloader to register class aliases for the classes that are migrated to namespaces, so that they are still accessible via the old name. This keeps everything working while migrating the classes.
parent 748daa08
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
* Autoload function for SimpleSAMLphp modules following PSR-0. * Autoload function for SimpleSAMLphp modules following PSR-0.
* *
* @param string $className Name of the class. * @param string $className Name of the class.
*
* TODO: this autoloader should be removed once everything has been migrated to namespaces.
*/ */
function SimpleSAML_autoload_psr0($className) function SimpleSAML_autoload_psr0($className)
{ {
...@@ -22,18 +24,30 @@ function SimpleSAML_autoload_psr0($className) ...@@ -22,18 +24,30 @@ function SimpleSAML_autoload_psr0($className)
} }
$modNameEnd = strpos($className, '_', $modulePrefixLength); $modNameEnd = strpos($className, '_', $modulePrefixLength);
$module = substr($className, $modulePrefixLength, $modNameEnd - $modulePrefixLength); $module = substr($className, $modulePrefixLength, $modNameEnd - $modulePrefixLength);
$moduleClass = substr($className, $modNameEnd + 1); $path = explode('_', substr($className, $modNameEnd + 1));
if (!SimpleSAML_Module::isModuleEnabled($module)) { if (!SimpleSAML_Module::isModuleEnabled($module)) {
return; return;
} }
$file = SimpleSAML_Module::getModuleDir($module).'/lib/'.str_replace('_', '/', $moduleClass).'.php'; $file = SimpleSAML_Module::getModuleDir($module).'/lib/'.join('/', $path).'.php';
if (file_exists($file)) { if (file_exists($file)) {
require_once($file); require_once($file);
} }
if (!class_exists($className, false)) {
// the file exists, but the class is not defined. Is it using namespaces?
$nspath = join('\\', $path);
if (class_exists('SimpleSAML\Module\\'.$module.'\\'.$nspath)) {
// the class has been migrated, create an alias and warn about it
SimpleSAML_Logger::warning(
"The class '$className' is now using namespaces, please use 'SimpleSAML\\Module\\$module\\".
"$nspath' instead."
);
class_alias("SimpleSAML\\Module\\$module\\$nspath", $className);
}
}
} }
......
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