collectRequestHostCandidates($request) as $host) { $match = $this->tunnelRegistry->findByRequestHost($host); if ($match !== null) { return (string) ($match['store_code'] ?? ''); } } return null; } /** * @return list */ private function collectRequestHostCandidates(Http $request): array { $seen = []; $out = []; foreach ($this->rawHostCandidates($request) as $raw) { $raw = trim($raw); if ($raw === '') { continue; } $hostKey = strtolower($raw); if (isset($seen[$hostKey])) { continue; } $seen[$hostKey] = true; $out[] = $raw; } return $out; } /** * @return list */ private function rawHostCandidates(Http $request): array { $candidates = []; $httpHost = $request->getServer('HTTP_HOST'); if ($httpHost !== null && $httpHost !== '') { $candidates[] = $httpHost; } $xForwardedHost = $request->getServer('HTTP_X_FORWARDED_HOST'); if ($xForwardedHost !== null && $xForwardedHost !== '') { foreach (explode(',', $xForwardedHost) as $part) { $candidates[] = trim($part); } } $header = $request->getHeader('X-Forwarded-Host'); if ($header !== false && $header !== null && trim((string) $header) !== '') { foreach (explode(',', (string) $header) as $part) { $candidates[] = trim($part); } } return $candidates; } public static function hostFromHttpHost(?string $httpHost): ?string { return TunnelRegistry::hostFromHttpHost($httpHost); } public static function hostFromBaseUrl(string $baseUrl): ?string { return TunnelRegistry::hostFromBaseUrl($baseUrl); } }