From 863e46d8f6776c5bae53cfd81516b35fb2fd979c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jaime=20Pe=CC=81rez=20Crespo?= <jaime.perez@uninett.no>
Date: Tue, 11 Dec 2018 14:16:20 +0100
Subject: [PATCH] bugfix: Allow loading the old sspmod_adfs_SAML2_XML_fed_Const
 class.

Since the class cannot be named "Const" when using namespaces, due to "const" being a reserved word, we needed to rename the class. That requires also some logic in the autoloader to map the old name to the new one.
---
 lib/_autoload_modules.php | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/lib/_autoload_modules.php b/lib/_autoload_modules.php
index 27c3bc89f..a8e04707b 100644
--- a/lib/_autoload_modules.php
+++ b/lib/_autoload_modules.php
@@ -87,9 +87,22 @@ function sspmodAutoloadPSR0($className)
         return;
     }
 
-    $modNameEnd = strpos($className, '_', $modulePrefixLength);
-    $module = substr($className, $modulePrefixLength, $modNameEnd - $modulePrefixLength);
-    $path = explode('_', substr($className, $modNameEnd + 1));
+    // list of classes that have been renamed or moved
+    $renamed = [
+        'sspmod_adfs_SAML2_XML_fed_Const' => [
+            'module' => 'adfs',
+            'path' => ['SAML2', 'XML', 'fed', 'Constants']
+        ],
+    ];
+    if (array_key_exists($className, $renamed)) {
+        // the class has been renamed, try to load it and create an alias
+        $module = $renamed[$className]['module'];
+        $path = $renamed[$className]['path'];
+    } else {
+        $modNameEnd = strpos($className, '_', $modulePrefixLength);
+        $module = substr($className, $modulePrefixLength, $modNameEnd - $modulePrefixLength);
+        $path = explode('_', substr($className, $modNameEnd + 1));
+    }
 
     if (!\SimpleSAML\Module::isModuleEnabled($module)) {
         return;
-- 
GitLab