Created
November 29, 2011 14:20
-
-
Save GromNaN/1404950 to your computer and use it in GitHub Desktop.
PSR-0 autoload.php
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
<?php | |
/** | |
* Simple autoloader that follow the PHP Standards Recommendation #0 (PSR-0) | |
* @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md for more informations. | |
* | |
* Code inspired from the SplClassLoader RFC | |
* @see https://wiki.php.net/rfc/splclassloader#example_implementation | |
*/ | |
spl_autoload_register(function($className) { | |
$package = 'Vendor'; | |
$className = ltrim($className, '\\'); | |
if (0 === strpos($className, $package)) { | |
$fileName = __DIR__ . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $className) . '.php'; | |
if (is_file($fileName)) { | |
require $fileName; | |
return true; | |
} | |
} | |
return false; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment