本文整理汇总了PHP中Psr\Http\Message\UriInterface::withScheme方法的典型用法代码示例。如果您正苦于以下问题:PHP UriInterface::withScheme方法的具体用法?PHP UriInterface::withScheme怎么用?PHP UriInterface::withScheme使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\UriInterface
的用法示例。
在下文中一共展示了UriInterface::withScheme方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildRouteUri
/**
* 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;
}
示例2: processProtoHeader
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;
}
示例3: generate
/**
* @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());
}
示例4: httpsRedirect
private function httpsRedirect(UriInterface $uri) : ResponseInterface
{
return new Response('php://memory', 307, ['Location' => strval($uri->withScheme('https')->withPort(443))]);
}
示例5: withScheme
/**
* 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');
}