From 6a12b80769640b2fe5ccd6f0f1219d9c2e8674df Mon Sep 17 00:00:00 2001
From: Jaime Perez Crespo <jaime.perez@uninett.no>
Date: Mon, 22 Feb 2016 13:55:56 +0100
Subject: [PATCH] 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.

---
 composer.json             |  4 ++--
 lib/_autoload_modules.php | 29 +++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/composer.json b/composer.json
index b4c998cd4..cc7ed22be 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 62aa262e4..c5524252b 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'));
-- 
GitLab