getParam(self::QUERY_PARAM_STORE); if ($value !== null && trim((string) $value) !== '') { return $this->onlyIfStoreExists(trim((string) $value)); } $value = $request->getHeader(self::HEADER_STORE_CODE); if ($value !== false && $value !== null && trim((string) $value) !== '') { return $this->onlyIfStoreExists(trim((string) $value)); } $value = $request->getServer(self::SERVER_HEADER); if ($value !== null && $value !== '' && trim((string) $value) !== '') { return $this->onlyIfStoreExists(trim((string) $value)); } $uri = (string) $request->getRequestUri(); if ($uri !== '' && str_contains($uri, self::QUERY_PARAM_STORE . '=')) { $query = str_contains($uri, '?') ? substr($uri, strpos($uri, '?') + 1) : ''; parse_str($query, $params); $v = $params[self::QUERY_PARAM_STORE] ?? ''; if ($v !== '' && trim((string) $v) !== '') { return $this->onlyIfStoreExists(trim((string) $v)); } } return $this->onlyIfStoreExists( $this->tunnelHostnameMatcher->getStoreCodeIfRequestHostMatchesState($request) ); } private function onlyIfStoreExists(?string $code): ?string { if ($code === null || $code === '') { return null; } try { $this->storeRepository->get($code); return $code; } catch (NoSuchEntityException) { return null; } } }