Created
February 9, 2011 19:33
-
-
Save alganet/819098 to your computer and use it in GitHub Desktop.
less javaish SplClassLoader
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($className) { | |
$fileParts = explode('\\', ltrim($className, '\\')); | |
if (false !== strpos(end($fileParts), '_')) | |
array_splice($fileParts, -1, 1, explode('_', current($fileParts))); | |
$file = implode(DIRECTORY_SEPARATOR, $fileParts) . '.php'; | |
foreach (explode(PATH_SEPARATOR, get_include_path()) as $path) { | |
if (file_exists($path = $path . DIRECTORY_SEPARATOR . $file)) | |
return require $path; | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Excelente exemplo de uso de funções anonimas. :)