summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJaime Perez Crespo <jaime.perez@uninett.no>2016-02-19 14:34:17 +0100
committerJaime Perez Crespo <jaime.perez@uninett.no>2016-02-19 14:34:17 +0100
commit07b6831248a79dacfacaf487965cbdfc643e5738 (patch)
tree14bdbf292bc69c3e35201e1c809b1d76e47909f6 /lib
parent748daa08ca671265e66ecc5121f93f3947dba8fa (diff)
downloadsimplesamlphp-07b6831248a79dacfacaf487965cbdfc643e5738.zip
simplesamlphp-07b6831248a79dacfacaf487965cbdfc643e5738.tar.gz
simplesamlphp-07b6831248a79dacfacaf487965cbdfc643e5738.tar.bz2
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/_autoload_modules.php22
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/_autoload_modules.php b/lib/_autoload_modules.php
index 773e5e1..77bfd81 100644
--- a/lib/_autoload_modules.php
+++ b/lib/_autoload_modules.php
@@ -12,6 +12,8 @@
* Autoload function for SimpleSAMLphp modules following PSR-0.
*
* @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)
{
@@ -22,18 +24,30 @@ function SimpleSAML_autoload_psr0($className)
}
$modNameEnd = strpos($className, '_', $modulePrefixLength);
- $module = substr($className, $modulePrefixLength, $modNameEnd - $modulePrefixLength);
- $moduleClass = substr($className, $modNameEnd + 1);
+ $module = substr($className, $modulePrefixLength, $modNameEnd - $modulePrefixLength);
+ $path = explode('_', substr($className, $modNameEnd + 1));
if (!SimpleSAML_Module::isModuleEnabled($module)) {
return;
}
- $file = SimpleSAML_Module::getModuleDir($module).'/lib/'.str_replace('_', '/', $moduleClass).'.php';
-
+ $file = SimpleSAML_Module::getModuleDir($module).'/lib/'.join('/', $path).'.php';
if (file_exists($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);
+ }
+ }
}