@@ -188,8 +188,8 @@ public function register()
188188 $ this ->registeredClosures [] = $ loadClassmap ;
189189 $ this ->registeredClosures [] = $ loadClass ;
190190
191- spl_autoload_register ($ loadClassmap , true );
192- spl_autoload_register ($ loadClass , true );
191+ spl_autoload_register ($ loadClassmap , prepend: true );
192+ spl_autoload_register ($ loadClass , prepend: true );
193193
194194 foreach ($ this ->files as $ file ) {
195195 $ this ->includeFile ($ file );
@@ -217,22 +217,24 @@ public function unregister(): void
217217 */
218218 public function addNamespace ($ namespace , ?string $ path = null )
219219 {
220- if (is_array ($ namespace )) {
221- foreach ($ namespace as $ prefix => $ namespacedPath ) {
222- $ prefix = trim ($ prefix , '\\' );
220+ if (is_string ($ namespace )) {
221+ if ($ path === null ) {
222+ return $ this ;
223+ }
223224
224- if (is_array ($ namespacedPath )) {
225- foreach ($ namespacedPath as $ dir ) {
226- $ this ->prefixes [$ prefix ][] = rtrim ($ dir , '\\/ ' ) . DIRECTORY_SEPARATOR ;
227- }
225+ $ namespace = [$ namespace => $ path ];
226+ }
228227
229- continue ;
230- }
228+ foreach ( $ namespace as $ prefix => $ paths ) {
229+ $ prefix = trim ( $ prefix , '\\' );
231230
232- $ this ->prefixes [$ prefix ][] = rtrim ($ namespacedPath , '\\/ ' ) . DIRECTORY_SEPARATOR ;
231+ if (is_string ($ paths )) {
232+ $ paths = [$ paths ];
233+ }
234+
235+ foreach ($ paths as $ path ) {
236+ $ this ->prefixes [$ prefix ][] = rtrim ($ path , '\\/ ' ) . DIRECTORY_SEPARATOR ;
233237 }
234- } else {
235- $ this ->prefixes [trim ($ namespace , '\\' )][] = rtrim ($ path , '\\/ ' ) . DIRECTORY_SEPARATOR ;
236238 }
237239
238240 return $ this ;
0 commit comments