@@ -55,6 +55,7 @@ public function locateFile(string $file, ?string $folder = null, string $ext = '
5555
5656 // Standardize slashes to handle nested directories.
5757 $ file = strtr ($ file , '/ ' , '\\' );
58+ $ file = ltrim ($ file , '\\' );
5859
5960 $ segments = explode ('\\' , $ file );
6061
@@ -64,23 +65,20 @@ public function locateFile(string $file, ?string $folder = null, string $ext = '
6465 }
6566
6667 $ paths = [];
67- $ prefix = '' ;
6868 $ filename = '' ;
6969
7070 // Namespaces always comes with arrays of paths
7171 $ namespaces = $ this ->autoloader ->getNamespace ();
7272
73- while (! empty ($ segments )) {
74- $ prefix .= empty ($ prefix ) ? array_shift ($ segments ) : '\\' . array_shift ($ segments );
73+ foreach (array_keys ($ namespaces ) as $ namespace ) {
74+ if (substr ($ file , 0 , strlen ($ namespace )) === $ namespace ) {
75+ // There may be sub-namespaces of the same vendor,
76+ // so overwrite them with namespaces found later.
77+ $ paths = $ namespaces [$ namespace ];
7578
76- if ( empty ( $ namespaces [ $ prefix ])) {
77- continue ;
79+ $ fileWithoutNamespace = substr ( $ file , strlen ( $ namespace ));
80+ $ filename = ltrim ( str_replace ( '\\' , ' / ' , $ fileWithoutNamespace ), ' / ' ) ;
7881 }
79-
80- $ paths = $ namespaces [$ prefix ];
81-
82- $ filename = implode ('/ ' , $ segments );
83- break ;
8482 }
8583
8684 // if no namespaces matched then quit
0 commit comments