Index of $uri"; echo '
'; echo implode("
".PHP_EOL, array_map(function ($path) use ($uri, $is_root) { $file = basename($path); return ($is_root) ? "/$file" : "$uri/$file/"; }, $paths)); exit; } /** * Extract site name from HTTP host, stripping www. and supporting wildcard DNS. * * @param string $httpHost * @return string */ public function siteNameFromHttpHost(string $httpHost): string { $siteName = basename( // Filter host to support wildcard dns feature $this->allowWildcardDnsDomains($httpHost), '.'.$this->config['tld'] ); if (strpos($siteName, 'www.') === 0) { $siteName = substr($siteName, 4); } return $siteName; } /** * You may use wildcard DNS provider nip.io as a tool for testing your site via an IP address. * First, determine the IP address of your local computer (like 192.168.0.10). * Then, visit http://project.your-ip.nip.io - e.g.: http://laravel.192.168.0.10.nip.io. * * @param string $domain * @return string */ public function allowWildcardDnsDomains(string $domain): string { $services = [ '.*.*.*.*.nip.io', '-*-*-*-*.nip.io', ]; if (isset($this->config['tunnel_services'])) { $services = array_merge($services, (array) $this->config['tunnel_services']); } $patterns = []; foreach ($services as $service) { $pattern = preg_quote($service, '#'); $pattern = str_replace('\*', '.*', $pattern); $patterns[] = '(.*)'.$pattern; } $pattern = implode('|', $patterns); if (preg_match('#(?:'.$pattern.')\z#u', $domain, $matches)) { $domain = array_pop($matches); } if (strpos($domain, ':') !== false) { $domain = explode(':', $domain)[0]; } return $domain; } /** * Determine the fully qualified path to the site. * Inspects registered path directories, case-sensitive. * * @param string $siteName * @return string|null */ public function sitePath(string $siteName): ?string { $valetSitePath = null; $domain = static::domainFromSiteName($siteName); foreach ($this->config['paths'] as $path) { $handle = opendir($path); if ($handle === false) { continue; } $dirs = []; while (false !== ($file = readdir($handle))) { if (is_dir($path.'/'.$file) && ! in_array($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; } } return null; } /** * Return the default site path for uncaught URLs, if it's set. * * @return string|null **/ public function defaultSitePath(): ?string { if (isset($this->config['default']) && is_string($this->config['default']) && is_dir($this->config['default'])) { return $this->config['default']; } return null; } }