Created
October 7, 2011 19:53
-
-
Save julianwachholz/1271217 to your computer and use it in GitHub Desktop.
A namespace based autoloader
This file contains hidden or 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 | |
spl_autoload_register(function($class) | |
{ | |
$path = str_replace('\\', DIRECTORY_SEPARATOR, $class); | |
// Convert the PascalCased names to snake_case | |
$path = preg_replace('/([a-z])([A-Z](?![A-Z]))/', '$1_$2', $path); | |
$path = strtolower($path); | |
$path = LIB_PATH . '/' . $path . '.php'; | |
require($path); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment