1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-04 16:10:08 +01:00

Avoid open file handles

And added comments for future maintenance
This commit is contained in:
Chris Brown
2021-06-14 14:57:06 -04:00
committed by GitHub
parent 43da6f5065
commit 2eb369b455

View File

@@ -130,22 +130,27 @@ function get_valet_site_path($valetConfig, $siteName, $domain)
$valetSitePath = null;
foreach ($valetConfig['paths'] as $path) {
if ($handle = opendir($path)) {
$dirs = [];
while (false !== ($file = readdir($handle))) {
if (! is_dir($path.'/'.$file)) continue;
if (in_array($file, ['.', '..', '.DS_Store'])) continue;
// match dir for lowercase, because Nginx only tells us lowercase names
if (strtolower($file) === $siteName) {
$valetSitePath = $path.'/'.$file;
break;
}
if (strtolower($file) === $domain) {
$valetSitePath = $path.'/'.$file;
}
$dirs[] = $file;
}
closedir($handle);
// Note: strtolower used below because Nginx only tells us lowercase names
foreach ($dirs as $dir) {
if (strtolower($dir) === $siteName) {
// early return when exact match for linked subdomain
return $path.'/'.$dir;
}
if (strtolower($dir) === $domain) {
// no early return here because the foreach may still have some subdomains to process with higher priority
$valetSitePath = $path.'/'.$dir;
}
}
if ($valetSitePath) {
return $valetSitePath;
}