1: <?php
2:
3: class IncludePath {
4:
5: private static $autoloadInitialized = false;
6:
7: public static function initAutoload() {
8: if (!self::$autoloadInitialized) {
9: spl_autoload_register(array('IncludePath', 'loadClass'));
10: self::$autoloadInitialized = true;
11: }
12: }
13:
14: public static function addPath($path) {
15: set_include_path(get_include_path() . PATH_SEPARATOR . $path);
16: }
17:
18: public static function loadClass($className) {
19: $className = ltrim($className, '\\');
20: $fileName = '';
21: $namespace = '';
22: if ($lastNsPos = strrpos($className, '\\')) {
23: $namespace = substr($className, 0, $lastNsPos);
24: $className = substr($className, $lastNsPos + 1);
25: $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
26: }
27: $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
28: return @include($fileName);
29: }
30:
31: }
32: