本文整理汇总了PHP中Psr\Http\Message\UriInterface::getHost方法的典型用法代码示例。如果您正苦于以下问题:PHP UriInterface::getHost方法的具体用法?PHP UriInterface::getHost怎么用?PHP UriInterface::getHost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\UriInterface
的用法示例。
在下文中一共展示了UriInterface::getHost方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleRequest
/**
* {@inheritdoc}
*/
public function handleRequest(RequestInterface $request, callable $next, callable $first)
{
if ($this->replace || $request->getUri()->getHost() === '') {
$uri = $request->getUri()->withHost($this->host->getHost())->withScheme($this->host->getScheme())->withPort($this->host->getPort());
$request = $request->withUri($uri);
}
return $next($request);
}
示例2: withUri
function withUri(UriInterface $uri, $preserveHost = FALSE) : self
{
$headers = $this->headers;
$headers['HOST'] = $headers['HOST'] ?? [];
if (!$preserveHost && $uri->getHost()) {
$headers['HOST'] = [$uri->getHost()];
}
$new = clone $this;
$new->headers = $headers;
$new->headerNames['HOST'] = 'Host';
$new->uri = parse_url((string) $uri);
return $new;
}
示例3: isFiltered
public function isFiltered(UriInterface $currentUri, UriInterface $startUri)
{
/* @var $currentUri Uri */
/* @var $startUri Uri */
$startDomainElements = explode('.', $startUri->getHost());
$currentDomainElements = explode('.', $currentUri->getHost());
$startDomainLength = count($startDomainElements);
$currentDomainLength = count($currentDomainElements);
if ($currentDomainLength < $startDomainLength) {
return true;
}
return $currentUri->getHost($startDomainLength) !== $startUri->getHost($startDomainLength);
}
示例4: withUri
public function withUri(UriInterface $uri, $preserveHost = false)
{
$request = clone $this;
$request->uri = $uri;
if ($preserveHost || !$uri->getHost()) {
return $request;
}
$host = $uri->getHost();
if ($uri->getPort()) {
$host .= ':' . $uri->getPort();
}
$request->withHeader('host', $host);
return $request;
}
示例5: withUri
public function withUri(Psr7UriInterface $uri, $preserveHost = false)
{
$new = clone $this;
$new->uri = $uri;
$uriHost = $uri->getHost();
$requestHost = $new->getHeaderLine('Host');
if (!$preserveHost && $uriHost !== $requestHost) {
return $new->withHeader('Host', $uriHost);
}
return $new;
}
示例6: withUri
public function withUri(\Psr\Http\Message\UriInterface $uri, $preserveHost = false)
{
$request = clone $this;
$request->uri = $uri;
if (!$preserveHost or !$this->hasHeader('Host')) {
$host = $uri->getHost();
if ($host != '') {
$request->setHeader('Host', $host);
}
}
return $request;
}
示例7: withUri
public function withUri(UriInterface $uri, $preserveHost = false)
{
$clone = clone $this;
$clone->uri = $uri;
if (!$preserveHost) {
if ($host = $uri->getHost()) {
if ($port = $uri->getPort()) {
$host .= ':' . $port;
}
return $clone->widthHeader('host', $host);
}
}
return $clone;
}
示例8: withUri
/**
* @param \Psr\Http\Message\UriInterface $uri
* @param bool $preserveHost
* @return static
*/
public function withUri(UriInterface $uri, $preserveHost = false)
{
$new = clone $this;
$new->uri = $uri;
if ($preserveHost || '' === ($host = $uri->getHost())) {
return $new;
}
if ('' !== ($port = $uri->getPort())) {
$host .= ':' . $port;
}
$new->headerNames['host'] = 'Host';
$new->headers['Host'] = [$host];
return $new;
}
示例9: withUri
public function withUri(\Psr\Http\Message\UriInterface $uri, $preserveHost = false)
{
if ($uri === $this->uri) {
return $this;
}
$new = clone $this;
$new->uri = $uri;
if ($preserveHost) {
return $new;
}
if ($host = $uri->getHost()) {
$new->updateFromUri($host);
}
return $new;
}
示例10: filterBaseurl
/**
* @param \Psr\Http\Message\UriInterface $uri
* @return string
*/
protected function filterBaseurl(UriInterface $uri)
{
if ($baseUrl = $this->settings['baseurl']) {
$reqUri = $uri->getScheme() . '://' . $uri->getHost();
if ($port = $uri->getPort()) {
$reqUri .= ':' . $port;
}
$url = parse_url($baseUrl);
$uri = $uri->withScheme($url['scheme'])->withHost($url['host']);
if ($port || isset($url['port'])) {
$port = $port == $url['port'] ? $port : $url['port'];
$uri = $uri->withPort($port);
}
return $reqUri !== rtrim($baseUrl, '/');
}
return false;
}
示例11: updateHostFromUri
/**
* Retrieve the host from the URI instance
*/
private function updateHostFromUri()
{
$host = $this->uri->getHost();
if ($host == '') {
return;
}
if (($port = $this->uri->getPort()) !== null) {
$host .= ':' . $port;
}
if (isset($this->headerNames['host'])) {
$header = $this->headerNames['host'];
} else {
$header = 'Host';
$this->headerNames['host'] = 'Host';
}
// Ensure Host is the first header.
// See: http://tools.ietf.org/html/rfc7230#section-5.4
$this->headers = [$header => [$host]] + $this->headers;
}
示例12: all
/**
* Get each invalidation request replicated over all HTTP caching servers
*
* @return RequestInterface[]
*/
public function all()
{
$requests = [];
foreach ($this->queue as $request) {
$uri = $request->getUri();
// If a base URI is configured, try to make partial invalidation
// requests complete.
if ($this->baseUri) {
if ($uri->getHost()) {
// Absolute URI: does it already have a scheme?
if (!$uri->getScheme() && $this->baseUri->getScheme() !== '') {
$uri = $uri->withScheme($this->baseUri->getScheme());
}
} else {
// Relative URI
if ($this->baseUri->getHost() !== '') {
$uri = $uri->withHost($this->baseUri->getHost());
}
if ($this->baseUri->getPort()) {
$uri = $uri->withPort($this->baseUri->getPort());
}
// Base path
if ($this->baseUri->getPath() !== '') {
$path = $this->baseUri->getPath() . '/' . ltrim($uri->getPath(), '/');
$uri = $uri->withPath($path);
}
}
}
// Close connections to make sure invalidation (PURGE/BAN) requests
// will not interfere with content (GET) requests.
$request = $request->withUri($uri)->withHeader('Connection', 'Close');
// Create a request to each caching proxy server
foreach ($this->servers as $server) {
$requests[] = $request->withUri($uri->withScheme($server->getScheme())->withHost($server->getHost())->withPort($server->getPort()), true);
}
}
return $requests;
}
示例13: getHostFromUri
/**
* Retrieve the host from the URI instance
*
* @return string
*/
private function getHostFromUri()
{
$host = $this->uri->getHost();
$host .= $this->uri->getPort() ? ':' . $this->uri->getPort() : '';
return $host;
}
示例14: withUri
/**
* {@inheritdoc}
*/
public function withUri(UriInterface $uri, $preserveHost = false)
{
$newInstance = clone $this;
$newInstance->uri = $uri;
if ($preserveHost) {
return $newInstance;
}
if ($uri->getHost() && !$this->hasHeader('Host')) {
$host = $uri->getHost();
$host .= !is_null($uri->getPort()) ? ':' . $uri->getPort() : '';
$newInstance->headerNames['host'] = 'Host';
$newInstance->headerValues['host'] = $host;
}
return $newInstance;
}
示例15: checkUrl
/**
* {@inheritDoc}
*/
public function checkUrl(UriInterface $uriInterface)
{
return preg_match('/imdb\\.com$/', (string) $uriInterface->getHost());
}