本文整理汇总了PHP中Psr\Http\Message\UriInterface::getPort方法的典型用法代码示例。如果您正苦于以下问题:PHP UriInterface::getPort方法的具体用法?PHP UriInterface::getPort怎么用?PHP UriInterface::getPort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\UriInterface
的用法示例。
在下文中一共展示了UriInterface::getPort方法的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
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;
}
示例3: updateHostFromUri
private function updateHostFromUri($host)
{
// Ensure Host is the first header.
// See: http://tools.ietf.org/html/rfc7230#section-5.4
if ($port = $this->uri->getPort()) {
$host .= ':' . $port;
}
$this->headerLines = array('Host' => array($host)) + $this->headerLines;
$this->headers = array('host' => array($host)) + $this->headers;
}
示例4: withUri
/**
* {@inheritdoc}
*/
public function withUri(UriInterface $uri, $preserveHost = false)
{
$cloneInstance = clone $this;
$cloneInstance->uri = $uri;
if ($preserveHost === false) {
if ($host = $uri->getHost()) {
if ($port = $this->uri->getPort()) {
$host .= ':' . $port;
}
$this->headers['host'] = ['name' => 'Host', 'value' => $host];
}
}
return $cloneInstance;
}
示例5: 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: 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;
}
示例9: 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;
}
示例10: resolve
/**
* Resolve a base URI with a relative URI and return a new URI.
*
* @param UriInterface $base Base URI
* @param string $rel Relative URI
*
* @return UriInterface
*/
public static function resolve(UriInterface $base, $rel)
{
if ($rel === null || $rel === '') {
return $base;
}
if ($rel instanceof UriInterface) {
$relParts = ['scheme' => $rel->getScheme(), 'host' => $rel->getHost(), 'port' => $rel->getPort(), 'path' => $rel->getPath(), 'query' => $rel->getQuery(), 'fragment' => $rel->getFragment()];
} else {
$relParts = parse_url($rel) + ['scheme' => '', 'host' => '', 'port' => '', 'path' => '', 'query' => '', 'fragment' => ''];
}
if (!empty($relParts['scheme']) && !empty($relParts['host'])) {
return $rel instanceof UriInterface ? $rel : self::fromParts($relParts);
}
$parts = ['scheme' => $base->getScheme(), 'host' => $base->getHost(), 'port' => $base->getPort(), 'path' => $base->getPath(), 'query' => $base->getQuery(), 'fragment' => $base->getFragment()];
if (!empty($relParts['host'])) {
$parts['host'] = $relParts['host'];
$parts['port'] = $relParts['port'];
$parts['path'] = self::removeDotSegments($relParts['path']);
$parts['query'] = $relParts['query'];
$parts['fragment'] = $relParts['fragment'];
} elseif (!empty($relParts['path'])) {
if (substr($relParts['path'], 0, 1) == '/') {
$parts['path'] = self::removeDotSegments($relParts['path']);
$parts['query'] = $relParts['query'];
$parts['fragment'] = $relParts['fragment'];
} else {
if (!empty($parts['host']) && empty($parts['path'])) {
$mergedPath = '/';
} else {
$mergedPath = substr($parts['path'], 0, strrpos($parts['path'], '/') + 1);
}
$parts['path'] = self::removeDotSegments($mergedPath . $relParts['path']);
$parts['query'] = $relParts['query'];
$parts['fragment'] = $relParts['fragment'];
}
} elseif (!empty($relParts['query'])) {
$parts['query'] = $relParts['query'];
} elseif ($relParts['fragment'] != null) {
$parts['fragment'] = $relParts['fragment'];
}
return static::fromParts($parts);
}
示例11: withUri
/**
* Returns an instance with the provided URI.
*
* This method MUST update the Host header of the returned request by
* default if the URI contains a host component. If the URI does not
* contain a host component, any pre-existing Host header MUST be carried
* over to the returned request.
*
* You can opt-in to preserving the original state of the Host header by
* setting `$preserveHost` to `true`. When `$preserveHost` is set to
* `true`, this method interacts with the Host header in the following ways:
*
* - If the the Host header is missing or empty, and the new URI contains
* a host component, this method MUST update the Host header in the returned
* request.
* - If the Host header is missing or empty, and the new URI does not contain a
* host component, this method MUST NOT update the Host header in the returned
* request.
* - If a Host header is present and non-empty, this method MUST NOT update
* the Host header in the returned request.
*
* @link http://tools.ietf.org/html/rfc3986#section-4.3
*
* @param UriInterface $uri New request URI to use.
* @param bool $preserveHost Preserve the original state of the Host header.
* @return self
*/
public function withUri(UriInterface $uri, $preserveHost = false)
{
$request = clone $this;
$request->scheme($uri->getScheme());
$userInfo = $uri->getUserInfo();
$parts = explode(':', $userInfo);
$request->username($parts[0] ?: null);
$request->password(!empty($parts[1]) ? $parts[1] : null);
$request->port($uri->getPort());
if ($preserveHost) {
$host = $request->headers['Host'];
$request->host($uri->getHost());
$request->headers['Host'] = $host;
} else {
$request->host($uri->getHost());
}
$request->path($uri->getPath());
$request->query($uri->getQuery());
$request->fragment($uri->getFragment());
return $request;
}
示例12: setBaseUriFromObject
/**
* @param UriInterface $baseUri
*/
protected function setBaseUriFromObject(UriInterface $baseUri)
{
$this->baseUri = ['scheme' => $baseUri->getScheme(), 'host' => $baseUri->getHost(), 'port' => $baseUri->getPort(), 'path' => rtrim($baseUri->getPath(), '/')];
}
示例13: withUri
/**
* @inheritdoc
*/
public function withUri(UriInterface $uri, $preserveHost = false)
{
$new = clone $this;
$new->url = $uri;
if ($preserveHost || !$uri->getHost()) {
return $new;
}
$host = $uri->getHost();
if ($uri->getPort()) {
$host .= ':' . $uri->getPort();
}
return $new->withHeader('Host', $host);
}
示例14: withUri
/**
* Returns an instance with the provided URI.
*
* This method MUST update the Host header of the returned request by
* default if the URI contains a host component. If the URI does not
* contain a host component, any pre-existing Host header MUST be carried
* over to the returned request.
*
* You can opt-in to preserving the original state of the Host header by
* setting `$preserveHost` to `true`. When `$preserveHost` is set to
* `true`, this method interacts with the Host header in the following ways:
*
* - If the the Host header is missing or empty, and the new URI contains
* a host component, this method MUST update the Host header in the returned
* request.
* - If the Host header is missing or empty, and the new URI does not contain a
* host component, this method MUST NOT update the Host header in the returned
* request.
* - If a Host header is present and non-empty, this method MUST NOT update
* the Host header in the returned request.
*
* This method MUST be implemented in such a way as to retain the
* immutability of the message, and MUST return an instance that has the
* new UriInterface instance.
*
* @link http://tools.ietf.org/html/rfc3986#section-4.3
*
* @param \Psr\Http\Message\UriInterface $uri New request URI to use.
* @param bool $preserveHost Preserve the original state of the Host header.
* @return Request
*/
public function withUri(UriInterface $uri, $preserveHost = FALSE)
{
$clonedObject = clone $this;
$clonedObject->uri = $uri;
if ($preserveHost) {
return $clonedObject;
}
if (!$uri->getHost()) {
return $clonedObject;
}
$host = $uri->getHost();
if ($uri->getPort()) {
$host .= ':' . $uri->getPort();
}
$clonedObject->headerNames['host'] = 'Host';
$clonedObject->headers['Host'] = array($host);
return $clonedObject;
}
示例15: setUri
/**
* Set the uri.
*
* @param UriInterface $uri
* @param boolean $preserveHost = false
* @return self
*/
private function setUri(UriInterface $uri, $preserveHost = false)
{
$this->uri = $uri;
if (!$preserveHost && ($host = $uri->getHost())) {
if ($uri->getPort() !== null) {
$host .= URI::DELIMITER_PORT . $uri->getPort();
}
$this->setHeader('Host', $host);
}
return $this;
}