| @@ 15-37 (lines=23) @@ | ||
| 12 | * @return void |
|
| 13 | */ |
|
| 14 | spl_autoload_register( |
|
| 15 | function ($class) { |
|
| 16 | // project-specific namespace prefix |
|
| 17 | $prefix = 'Anax\\'; |
|
| 18 | // base directory for the namespace prefix |
|
| 19 | $base_dir = __DIR__ . '/src/'; |
|
| 20 | // does the class use the namespace prefix? |
|
| 21 | $len = strlen($prefix); |
|
| 22 | if (strncmp($prefix, $class, $len) !== 0) { |
|
| 23 | // no, move to the next registered autoloader |
|
| 24 | return; |
|
| 25 | } |
|
| 26 | // get the relative class name |
|
| 27 | $relative_class = substr($class, $len); |
|
| 28 | // replace the namespace prefix with the base directory, replace namespace |
|
| 29 | // separators with directory separators in the relative class name, append |
|
| 30 | // with .php |
|
| 31 | $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php'; |
|
| 32 | // if the file exists, require it |
|
| 33 | if (file_exists($file)) { |
|
| 34 | include $file; |
|
| 35 | } |
|
| 36 | } |
|
| 37 | ); |
|
| 38 | ||
| 39 | ||
| 40 | // autoloader for 'Psr\' |
|
| @@ 42-64 (lines=23) @@ | ||
| 39 | ||
| 40 | // autoloader for 'Psr\' |
|
| 41 | spl_autoload_register( |
|
| 42 | function ($class) { |
|
| 43 | // project-specific namespace prefix |
|
| 44 | $prefix = 'Psr\\'; |
|
| 45 | // base directory for the namespace prefix |
|
| 46 | $base_dir = __DIR__ . '/src/'; |
|
| 47 | // does the class use the namespace prefix? |
|
| 48 | $len = strlen($prefix); |
|
| 49 | if (strncmp($prefix, $class, $len) !== 0) { |
|
| 50 | // no, move to the next registered autoloader |
|
| 51 | return; |
|
| 52 | } |
|
| 53 | // get the relative class name |
|
| 54 | $relative_class = substr($class, $len); |
|
| 55 | // replace the namespace prefix with the base directory, replace namespace |
|
| 56 | // separators with directory separators in the relative class name, append |
|
| 57 | // with .php |
|
| 58 | $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php'; |
|
| 59 | // if the file exists, require it |
|
| 60 | if (file_exists($file)) { |
|
| 61 | include $file; |
|
| 62 | } |
|
| 63 | } |
|
| 64 | ); |
|
| 65 | ||