| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/**
|
|
|
4 |
* Simple autoloader that follow the PHP Standards Recommendation #0 (PSR-0)
|
|
|
5 |
*
|
|
|
6 |
* @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md for more informations.
|
|
|
7 |
*
|
|
|
8 |
* Code inspired from the SplClassLoader RFC
|
|
|
9 |
* @see https://wiki.php.net/rfc/splclassloader#example_implementation
|
|
|
10 |
*/
|
|
|
11 |
spl_autoload_register(function ($className) {
|
|
|
12 |
$className = ltrim($className, '\\');
|
|
|
13 |
$fileName = '';
|
|
|
14 |
|
|
|
15 |
if ($lastNsPos = strripos($className, '\\')) {
|
|
|
16 |
$namespace = substr($className, 0, $lastNsPos);
|
|
|
17 |
$className = substr($className, $lastNsPos + 1);
|
|
|
18 |
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
|
|
|
19 |
}
|
|
|
20 |
$fileName = __DIR__ . DIRECTORY_SEPARATOR . $fileName . $className . '.php';
|
|
|
21 |
|
|
|
22 |
if (file_exists($fileName)) {
|
|
|
23 |
require $fileName;
|
|
|
24 |
|
|
|
25 |
return true;
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
return false;
|
|
|
29 |
});
|