/** * Builds URI for provided route instance. * * @param RouteContract $route * @param array $variables * @param array $query * @return UriInterface */ private function buildRouteUri(RouteContract $route, array $variables = [], array $query = []) : UriInterface { $uri = $this->uri->withScheme($route->getScheme() ?: $this->request->getUri()->getScheme())->withHost($route->getHost() ?: $this->request->getUri()->getHost())->withPath($route->compilePath($variables)); if ($query) { $uri = $uri->withQuery(http_build_query($query)); } return $uri; }
protected function processProtoHeader(ServerRequestInterface $request, UriInterface $uri) { if ($request->hasHeader('X-Forwarded-Proto')) { $scheme = $request->getHeaderLine('X-Forwarded-Proto'); if (in_array($scheme, ['http', 'https'])) { return $uri->withScheme($scheme); } } return $uri; }
/** * @param LeagueUriInterface|UriInterface $relative * * @return LeagueUriInterface|UriInterface */ protected function generate($relative) { $scheme = $relative->getScheme(); if (!empty($scheme) && $scheme != $this->uri->getScheme()) { return $relative; } if (!empty($relative->getAuthority())) { return $relative->withScheme($this->uri->getScheme()); } return $this->resolveRelative($relative)->withFragment($relative->getFragment()); }
private function httpsRedirect(UriInterface $uri) : ResponseInterface { return new Response('php://memory', 307, ['Location' => strval($uri->withScheme('https')->withPort(443))]); }
/** * Create an UriInterface with the scheme information from `$server`. It uses `$server['HTTPS']` to determine the * scheme. * * @param UriInterface $uri * @param array $server * * @return UriInterface */ private function withScheme(UriInterface $uri, array $server) : UriInterface { if (isset($server['HTTPS'])) { return $uri->withScheme($server['HTTPS'] == 'on' ? 'https' : 'http'); } return $uri->withScheme('http'); }