Skip to content

Commit 3345b84

Browse files
authored
Move foreach into separated function
1 parent c2f21a4 commit 3345b84

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

server.php

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -125,28 +125,32 @@ function valet_default_site_path($config)
125125
* Determine the fully qualified path to the site.
126126
* Inspects registered path directories, case-sensitive.
127127
*/
128-
$valetSitePath = null;
129-
$domain = array_slice(explode('.', $siteName), -1)[0];
130-
131-
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;
128+
function get_valet_site_path($valtetConfig, $domain, $siteName)
129+
{
130+
$valetSitePath = null;
131+
foreach ($valtetConfig['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+
}
141+
}
142+
closedir($handle);
143+
144+
if ($valetSitePath) {
145+
return $valetSitePath;
140146
}
141-
}
142-
closedir($handle);
143-
144-
if ($valetSitePath) {
145-
break;
146147
}
147148
}
148149
}
149150

151+
$domain = array_slice(explode('.', $siteName), -1)[0];
152+
$valetSitePath = get_valet_site_path($valetConfig, $siteName, $domain);
153+
150154
if (is_null($valetSitePath) && is_null($valetSitePath = valet_default_site_path($valetConfig))) {
151155
show_valet_404();
152156
}

0 commit comments

Comments
 (0)