@@ -128,23 +128,40 @@ function valet_default_site_path($config)
128128function get_valet_site_path ($ valetConfig , $ siteName , $ domain )
129129{
130130 $ valetSitePath = null ;
131+
131132 foreach ($ valetConfig ['paths ' ] as $ path ) {
132- if ($ handle = opendir ($ path )) {
133- while (false !== ($ file = readdir ($ handle ))) {
134- if (! is_dir ($ path .'/ ' .$ file )) continue ;
135- if (in_array ($ file , ['. ' , '.. ' , '.DS_Store ' ])) continue ;
136-
137- // match dir for lowercase, because Nginx only tells us lowercase names
138- if (strtolower ($ file ) === $ siteName || strtolower ($ file ) === $ domain ) {
139- $ valetSitePath = $ path .'/ ' .$ file ;
140- }
133+ $ handle = opendir ($ path );
134+
135+ if ($ handle === false ) {
136+ continue ;
137+ }
138+
139+ $ dirs = [];
140+
141+ while (false !== ($ file = readdir ($ handle ))) {
142+ if (is_dir ($ path .'/ ' .$ file ) && ! in_array ($ file , ['. ' , '.. ' ])) {
143+ $ dirs [] = $ file ;
144+ }
145+ }
146+
147+ closedir ($ handle );
148+
149+ // Note: strtolower used below because Nginx only tells us lowercase names
150+ foreach ($ dirs as $ dir ) {
151+ if (strtolower ($ dir ) === $ siteName ) {
152+ // early return when exact match for linked subdomain
153+ return $ path .'/ ' .$ dir ;
141154 }
142- closedir ( $ handle );
143-
144- if ( $ valetSitePath ) {
145- return $ valetSitePath ;
155+
156+ if ( strtolower ( $ dir ) === $ domain ) {
157+ // no early return here because the foreach may still have some subdomains to process with higher priority
158+ $ valetSitePath = $ path . ' / ' . $ dir ;
146159 }
147160 }
161+
162+ if ($ valetSitePath ) {
163+ return $ valetSitePath ;
164+ }
148165 }
149166}
150167
0 commit comments