1 | <?php |
||
11 | class Autoloader |
||
12 | { |
||
13 | use LoggedClassTrait; |
||
14 | |||
15 | protected $packages = array(); |
||
16 | |||
17 | /** |
||
18 | * Registers the includeClass function as an autoloader. |
||
19 | * |
||
20 | * @see Autoloader::includeClass |
||
21 | * |
||
22 | * @return void |
||
23 | */ |
||
24 | 2 | public function register() |
|
28 | |||
29 | /** |
||
30 | * Registers a given package with an associated path. |
||
31 | * |
||
32 | * Duplicate package/path combinations will not be re-registered. |
||
33 | * |
||
34 | * @param string $package The name of the package to be registered |
||
35 | * @param string $path The path to be associated with the registered package |
||
36 | * |
||
37 | * @return void |
||
38 | */ |
||
39 | 14 | public function registerPackages($package, $path) |
|
57 | |||
58 | /** |
||
59 | * Returns an array of registered packages. |
||
60 | * |
||
61 | * @return array |
||
62 | */ |
||
63 | 9 | public function getRegisteredPackages() |
|
67 | |||
68 | /** |
||
69 | * Includes the file corresponding with the class name to be autoloaded |
||
70 | * |
||
71 | * @param string $class Class name as defined by PHP autoloading |
||
72 | * |
||
73 | * @return void |
||
74 | */ |
||
75 | 3 | protected function includeClass($class) |
|
96 | |||
97 | /** |
||
98 | * Attempts to load a class from a stack of packages |
||
99 | * |
||
100 | * @param string $class The fully-qualified class name |
||
101 | * @param array $package_stack A stack of packages for loading |
||
102 | * |
||
103 | * @return bool Returns true if the class was successfully loaded from the package stack |
||
104 | * Returns false if the class could not be loaded from the package stack |
||
105 | */ |
||
106 | 3 | protected function loadPackageStack($class, array $package_stack) |
|
127 | |||
128 | /** |
||
129 | * Loads a package based on registered paths associated with the package. |
||
130 | * |
||
131 | * @param string $package_name The name of the package in Vendor\Package format |
||
132 | * @param string $class_name The full, relative name of the class with the vendor and package names stripped |
||
133 | * |
||
134 | * @return bool The path to the class on success; otherwise false |
||
135 | */ |
||
136 | 2 | protected function loadPackage($package_name, $class_name) |
|
153 | |||
154 | /** |
||
155 | * Determines whether a given package is registered with the Autoloader |
||
156 | * |
||
157 | * @param string $package The package to check |
||
158 | * |
||
159 | * @return bool Returns true if the given package is registered |
||
160 | * Returns false if the given package is not registered |
||
161 | */ |
||
162 | 14 | private function packageRegistered($package) |
|
174 | |||
175 | /** |
||
176 | * Determines whether a given package/path combination has already been registered with the Autoloader |
||
177 | * |
||
178 | * @param string $package The package to check |
||
179 | * @param string $path The path to check |
||
180 | * |
||
181 | * @return bool Returns true if the given path has been registered with the given package |
||
182 | * Returns false if the given path has not been registered with the given package |
||
183 | */ |
||
184 | 14 | private function registrationExists($package, $path) |
|
202 | |||
203 | /** |
||
204 | * Requires a file only if it existss |
||
205 | * |
||
206 | * @param string $path The path to the file for requiring |
||
207 | * |
||
208 | * @return bool Returns true if the file at the given path exists |
||
209 | * Returns false if the file at the given path does not exist |
||
210 | */ |
||
211 | 2 | private function requireFile($path) |
|
228 | } |
||
229 |