@@ -170,8 +170,8 @@ private function loadComposerAutoloader(Modules $modules): void
170170 */
171171 public function register ()
172172 {
173- spl_autoload_register ($ this ->loadClassmap (...), true );
174- spl_autoload_register ($ this ->loadClass (...), true );
173+ spl_autoload_register ($ this ->loadClass (...), prepend: true );
174+ spl_autoload_register ($ this ->loadClassmap (...), prepend: true );
175175
176176 foreach ($ this ->files as $ file ) {
177177 $ this ->includeFile ($ file );
@@ -196,22 +196,24 @@ public function unregister(): void
196196 */
197197 public function addNamespace ($ namespace , ?string $ path = null )
198198 {
199- if (is_array ($ namespace )) {
200- foreach ($ namespace as $ prefix => $ namespacedPath ) {
201- $ prefix = trim ($ prefix , '\\' );
199+ if (is_string ($ namespace )) {
200+ if ($ path === null ) {
201+ return $ this ;
202+ }
202203
203- if (is_array ($ namespacedPath )) {
204- foreach ($ namespacedPath as $ dir ) {
205- $ this ->prefixes [$ prefix ][] = rtrim ($ dir , '\\/ ' ) . DIRECTORY_SEPARATOR ;
206- }
204+ $ namespace = [$ namespace => $ path ];
205+ }
207206
208- continue ;
209- }
207+ foreach ( $ namespace as $ prefix => $ paths ) {
208+ $ prefix = trim ( $ prefix , '\\' );
210209
211- $ this ->prefixes [$ prefix ][] = rtrim ($ namespacedPath , '\\/ ' ) . DIRECTORY_SEPARATOR ;
210+ if (is_string ($ paths )) {
211+ $ paths = [$ paths ];
212+ }
213+
214+ foreach ($ paths as $ path ) {
215+ $ this ->prefixes [$ prefix ][] = rtrim ($ path , '\\/ ' ) . DIRECTORY_SEPARATOR ;
212216 }
213- } else {
214- $ this ->prefixes [trim ($ namespace , '\\' )][] = rtrim ($ path , '\\/ ' ) . DIRECTORY_SEPARATOR ;
215217 }
216218
217219 return $ this ;
0 commit comments