Created
April 13, 2015 10:23
-
-
Save Sketches-su/b5090e2284324bfc211e to your computer and use it in GitHub Desktop.
Quick&dirty PSR-0 implementation (tested)
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
spl_autoload_register(function ($class) | |
{ | |
$file = __DIR__.DIRECTORY_SEPARATOR.'classes'.DIRECTORY_SEPARATOR; | |
if ($class[0] == '\\') { | |
$class = ltrim($class, '\\'); | |
} | |
if (false !== ($pos = strrpos($class, '\\'))) { | |
$file .= str_replace( | |
'\\', | |
DIRECTORY_SEPARATOR, | |
substr($class, 0, ++$pos) | |
); | |
} | |
$file .= str_replace( | |
'_', | |
DIRECTORY_SEPARATOR, | |
$pos ? substr($class, $pos) : $class | |
).'.php'; | |
if (file_exists($file)) { | |
require $file; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment