Created
July 9, 2013 00:52
-
-
Save Ferreiramg/5953774 to your computer and use it in GitHub Desktop.
psr-0 autoload
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
define("DS", DIRECTORY_SEPARATOR); | |
set_include_path( | |
implode(PATH_SEPARATOR, array(dirname(__DIR__), get_include_path()) | |
)); | |
$psr = array( | |
'\\' => DS, | |
'_' => DS | |
); | |
spl_autoload_register(function($class)use($psr) { | |
$filename = strtr($class, $psr) . ".php"; | |
foreach (explode(PATH_SEPARATOR, get_include_path()) as $paths) { | |
$paths .=DS . $filename; | |
if (is_file($paths)) { | |
require_once $paths; | |
return true; | |
} | |
} | |
return false; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment