1 | <?php |
||
27 | class Autoloader |
||
28 | { |
||
29 | /** |
||
30 | * @var string Constant for namespace separator |
||
31 | */ |
||
32 | const NAMESPACE_SEPARATOR = '\\'; |
||
33 | |||
34 | /** |
||
35 | * An array of paths that will be searched when attempting to load a class. |
||
36 | * |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $paths; |
||
40 | |||
41 | /** |
||
42 | * Autoloader Constructor. |
||
43 | * |
||
44 | * @param array $paths Paths to search for classes |
||
45 | */ |
||
46 | 8 | public function __construct($paths = []) |
|
53 | |||
54 | /** |
||
55 | * Add path to list of search paths. |
||
56 | * |
||
57 | * Attempts to deduce the absolute (real) path from the path specified by the |
||
58 | * $path argument. If successful, the absolute path is added to the search |
||
59 | * path list and the method returns true. If one can't be found, it adds $path |
||
60 | * to the search path list, as-is and returns false |
||
61 | * |
||
62 | * @param string $path A path to add to the list of search paths |
||
63 | * |
||
64 | * @return bool |
||
65 | */ |
||
66 | 5 | public function addPath($path) |
|
81 | |||
82 | /** |
||
83 | * Retrieve search path list (array). |
||
84 | * |
||
85 | * Simply returns the array containing all the paths that will be searched |
||
86 | * when attempting to load a class. |
||
87 | * |
||
88 | * @return array An array of paths to search for classes |
||
89 | */ |
||
90 | 106 | public function getPaths() |
|
94 | |||
95 | /** |
||
96 | * Register the autoloader. |
||
97 | * |
||
98 | * Registers this library's autoload function with the SPL-provided autoload |
||
99 | * queue. This allows for CSVelte's autoloader to work its magic without |
||
100 | * having to worry about interfering with any other autoloader. |
||
101 | * |
||
102 | * Also adds all of this class's search paths to PHP's include path. |
||
103 | * |
||
104 | * @return bool Whatever the return value of spl_autoload_register is |
||
105 | * |
||
106 | * @see spl_autoload_register |
||
107 | */ |
||
108 | 2 | public function register() |
|
113 | |||
114 | /** |
||
115 | * Load a class. |
||
116 | * |
||
117 | * This is the function (or method in this case) used to autoload all of |
||
118 | * CSVelte's classes. It need not be called directly, but rather regestered |
||
119 | * with the SPL's autoload queue using this class's register method. |
||
120 | * |
||
121 | * @param string $className The fully qualified class name to load |
||
122 | * |
||
123 | * @return bool |
||
124 | * |
||
125 | * @see Autoloader::register() |
||
126 | */ |
||
127 | 103 | public function load($className) |
|
143 | } |
||
144 |