Skip to content

Commit

Permalink
Merge branch 'master' into release-2.x
Browse files Browse the repository at this point in the history
* 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
jaimeperez committed Mar 16, 2016
2 parents d78becc + 2112190 commit 0d6861b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"autoload": {
"psr-0": {
"SAML2\\": "src/"
}
},
"files": ["src/_autoload.php"]
},
"autoload-dev": {
"psr-0": {
Expand Down
35 changes: 35 additions & 0 deletions src/_autoload.php
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');

0 comments on commit 0d6861b

Please sign in to comment.