-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into release-2.x
* master: Put the autoloader to work. Add an autoloader that allows using the old class names even after migrating to PSR-2. This makes it easier for projects using the library to migrate, as it can then be done incrementally.
- Loading branch information
Showing
2 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/** | ||
* Temporary autoloader to ensure compatibility with old, non-PSR-2 compliant classes. | ||
* | ||
* @author Jaime Pérez Crespo <jaime.perez@uninett.no> | ||
* @package SimpleSAMLphp | ||
*/ | ||
|
||
/** | ||
* Autoload function that looks for classes migrated to PSR-2. | ||
* | ||
* @param string $className Name of the class. | ||
*/ | ||
function SAML2_autoload($className) | ||
{ | ||
// handle classes that have been renamed | ||
$renamed = array( | ||
'SAML2_Const' => 'SAML2_Constants', | ||
); | ||
$oldName = $className; | ||
if (array_key_exists($className, $renamed)) { | ||
$className = $renamed[$className]; | ||
} | ||
|
||
$file = dirname(__FILE__).'/'.str_replace('_', '/', $className).'.php'; | ||
if (file_exists($file)) { | ||
require_once($file); | ||
$newName = '\\'.str_replace('_', '\\', $className); | ||
class_alias($newName, $oldName); | ||
} | ||
|
||
} | ||
|
||
spl_autoload_register('SAML2_autoload'); |