Last active
March 3, 2016 12:49
-
-
Save jesseschalken/26de0fb81b63452f27f5 to your computer and use it in GitHub Desktop.
This autoloader will search for Foo\Bar\Baz (for example) in ./Foo/Bar/Baz.php, ./Foo/Bar.php and ./Foo.php, in that order. This enables developers to place multiple classes and even multiple namespaces in one file when appropriate. Just place this file in your src/ directory and use it as the entry point for your project.
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 | |
spl_autoload_register(function ($cls) { | |
for ($cls = explode('\\', $cls); $cls; array_pop($cls)) { | |
$sep = DIRECTORY_SEPARATOR; | |
$php = __DIR__ . $sep . join($sep, $cls) . '.php'; | |
if (file_exists($php)) { | |
/** @noinspection PhpIncludeInspection */ | |
require_once $php; | |
break; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment