@@ -128,33 +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- $ dirs = [];
134- while (false !== ($ file = readdir ($ handle ))) {
135- if (! is_dir ($ path .'/ ' .$ file )) continue ;
136- if (in_array ($ file , ['. ' , '.. ' , '.DS_Store ' ])) continue ;
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 , ['. ' , '.. ' , '.DS_Store ' ])) {
137143 $ dirs [] = $ file ;
138144 }
139- closedir ($ handle );
140-
141- // Note: strtolower used below because Nginx only tells us lowercase names
142- foreach ($ dirs as $ dir ) {
143- if (strtolower ($ dir ) === $ siteName ) {
144- // early return when exact match for linked subdomain
145- return $ path .'/ ' .$ dir ;
146- }
147-
148- if (strtolower ($ dir ) === $ domain ) {
149- // no early return here because the foreach may still have some subdomains to process with higher priority
150- $ valetSitePath = $ path .'/ ' .$ dir ;
151- }
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 ;
152154 }
153155
154- if ($ valetSitePath ) {
155- return $ valetSitePath ;
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 ;
156159 }
157160 }
161+
162+ if ($ valetSitePath ) {
163+ return $ valetSitePath ;
164+ }
158165 }
159166}
160167
0 commit comments