1 | <?php |
||
36 | class Autoloader { |
||
37 | |||
38 | /** @var boolean */ |
||
39 | private $isRegistered; |
||
40 | |||
41 | /** @var boolean */ |
||
42 | private $prependAutoloader; |
||
43 | |||
44 | /** @var array */ |
||
45 | private $namespaces; |
||
46 | |||
47 | /** |
||
48 | * Class constructor. |
||
49 | * @param array $namespaces the namespaces to register as namespace => path structure. |
||
50 | * @param boolean $prepend flag to prepend or append to the PHP autoloader list |
||
51 | * @throws \InvalidArgumentException if an argument is not valid |
||
52 | * @throws \Brickoo\Component\Common\Exception\DirectoryDoesNotExistException |
||
53 | * @throws \Brickoo\Component\Common\Exception\DuplicateNamespaceRegistrationException |
||
54 | */ |
||
55 | 1 | public function __construct(array $namespaces = [], $prepend = true) { |
|
65 | |||
66 | /** |
||
67 | * Register the autoloader. |
||
68 | * @return \Brickoo\Component\Common\Autoloader |
||
69 | */ |
||
70 | 1 | public function register() { |
|
78 | |||
79 | /** |
||
80 | * Unregister the autoloader. |
||
81 | * @return \Brickoo\Component\Common\Autoloader |
||
82 | */ |
||
83 | 1 | public function unregister() { |
|
91 | |||
92 | /** |
||
93 | * Register the namespace to the available namespaces. |
||
94 | * @param string $namespace the namespace to register |
||
95 | * @param string $namespacePath the absolute path to the namespace |
||
96 | * @throws Exception\DirectoryDoesNotExistException |
||
97 | * @throws Exception\DuplicateNamespaceRegistrationException |
||
98 | * @throws \InvalidArgumentException if an argument is not valid |
||
99 | * @return \Brickoo\Component\Common\Autoloader |
||
100 | */ |
||
101 | 5 | public function registerNamespace($namespace, $namespacePath) { |
|
113 | |||
114 | /** |
||
115 | * Check if the given namespace has been registered. |
||
116 | * @param string $namespace the namespace to check |
||
117 | * @throws \InvalidArgumentException if an argument is not valid |
||
118 | * @return boolean check result |
||
119 | */ |
||
120 | 2 | public function isNamespaceRegistered($namespace) { |
|
124 | |||
125 | /** |
||
126 | * Return the registered namespaces. |
||
127 | * @return array the registered namespaces |
||
128 | */ |
||
129 | 1 | public function getRegisteredNamespaces() { |
|
132 | |||
133 | /** |
||
134 | * Load the requested class. |
||
135 | * Commonly this is the auto loader callback function registered. |
||
136 | * @param string $className the class to load |
||
137 | * @return boolean true on success false on failure |
||
138 | */ |
||
139 | 5 | public function load($className) { |
|
148 | |||
149 | /** |
||
150 | * Validate the namespace. |
||
151 | * @param string $namespace |
||
152 | * @throws \InvalidArgumentException |
||
153 | * @return void |
||
154 | */ |
||
155 | 2 | private function validateNamespace($namespace) { |
|
160 | |||
161 | /** |
||
162 | * Validate the namespace path. |
||
163 | * @param string $namespacePath |
||
164 | * @throws \Brickoo\Component\Common\Exception\DirectoryDoesNotExistException |
||
165 | * @throws \InvalidArgumentException |
||
166 | * @return void |
||
167 | */ |
||
168 | 3 | private function validateNamespacePath($namespacePath) { |
|
178 | |||
179 | /** |
||
180 | * Returns the path for a namespace class. |
||
181 | * @param string $className |
||
182 | * @return string|null the namespace based path otherwise null |
||
183 | */ |
||
184 | 3 | private function getNamespaceClassPath($className) { |
|
197 | |||
198 | /** |
||
199 | * Create the class filesystem loader path. |
||
200 | * @param string $className |
||
201 | * @param string $chosenNamespace |
||
202 | * @param string $chosenPath |
||
203 | * @return null|string the class path otherwise null |
||
204 | */ |
||
205 | 3 | private function createClassPath($className, $chosenNamespace, $chosenPath) { |
|
211 | |||
212 | /** |
||
213 | * Returns a translated namespace class to filesystem path. |
||
214 | * @param string $className class including namespace |
||
215 | * @return string the translated class path |
||
216 | */ |
||
217 | 3 | private function getTranslatedClassPath($className) { |
|
221 | |||
222 | } |
||
223 |