本文整理汇总了PHP中Psr\Http\Message\UriInterface::getScheme方法的典型用法代码示例。如果您正苦于以下问题:PHP UriInterface::getScheme方法的具体用法?PHP UriInterface::getScheme怎么用?PHP UriInterface::getScheme使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\UriInterface
的用法示例。
在下文中一共展示了UriInterface::getScheme方法的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: fetchNode
/**
* @param $nodes
* @param $uri
* @return mixed
* @throws UnableToDetermineNodesException
* @throws UnknownNodeTypeException
*/
protected function fetchNode(array $nodes, UriInterface $uri)
{
foreach ($nodes as $nodeId => $node) {
if (!isset($node['type']) || !isset($node['pattern'])) {
continue;
}
if (strpos($node['type'], 'url') !== 0) {
continue;
}
if (strpos($uri->getScheme(), 'http') !== 0) {
continue;
}
$type = $node['type'];
$pattern = $node['pattern'];
$subject = NULL;
//check if https is required
if (isset($node['secure'])) {
if ($node['secure'] && strpos($uri->getScheme(), 'https') !== 0) {
continue;
}
}
//determine url part by type
switch ($type) {
case "url":
$subject = $uri;
break;
case "url_path":
$subject = $uri->getPath();
break;
case "url_host":
$subject = $uri->getHost();
break;
case "url_query":
$subject = $uri->getQuery();
break;
default:
throw new UnknownNodeTypeException($type);
}
if (preg_match_all('#' . $pattern . '#i', $subject)) {
return [$nodeId, $node];
}
}
throw new UnableToDetermineNodesException();
}
示例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: 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;
}
示例5: 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;
}
示例6: isSecure
/**
* Check if the given URL has an https:// protocol scheme.
*
* @param \Psr\Http\Message\UriInterface $uri
* @return bool
*/
protected function isSecure(UriInterface $uri)
{
return strtolower($uri->getScheme()) === 'https';
}
示例7: formatUri
/**
* Format an Uri according to the Formatter properties
*
* @param Uri|UriInterface $uri
*
* @return string
*/
protected function formatUri($uri)
{
$scheme = $uri->getScheme();
if ('' !== $scheme) {
$scheme .= ':';
}
$auth = $this->formatAuthority($uri);
return $scheme . $auth . $this->formatPath($uri->getPath(), $auth) . $this->formatQuery($uri) . $this->formatFragment($uri);
}
示例8: relativize
/**
* Returns the target URI as a relative reference from the base URI.
*
* This method is the counterpart to resolve():
*
* (string) $target === (string) UriResolver::resolve($base, UriResolver::relativize($base, $target))
*
* One use-case is to use the current request URI as base URI and then generate relative links in your documents
* to reduce the document size or offer self-contained downloadable document archives.
*
* $base = new Uri('http://example.com/a/b/');
* echo UriResolver::relativize($base, new Uri('http://example.com/a/b/c')); // prints 'c'.
* echo UriResolver::relativize($base, new Uri('http://example.com/a/x/y')); // prints '../x/y'.
* echo UriResolver::relativize($base, new Uri('http://example.com/a/b/?q')); // prints '?q'.
* echo UriResolver::relativize($base, new Uri('http://example.org/a/b/')); // prints '//example.org/a/b/'.
*
* This method also accepts a target that is already relative and will try to relativize it further. Only a
* relative-path reference will be returned as-is.
*
* echo UriResolver::relativize($base, new Uri('/a/b/c')); // prints 'c' as well
*
* @param UriInterface $base Base URI
* @param UriInterface $target Target URI
*
* @return UriInterface The relative URI reference
*/
public static function relativize(UriInterface $base, UriInterface $target)
{
if ($target->getScheme() !== '' && ($base->getScheme() !== $target->getScheme() || $target->getAuthority() === '' && $base->getAuthority() !== '')) {
return $target;
}
if (Uri::isRelativePathReference($target)) {
// As the target is already highly relative we return it as-is. It would be possible to resolve
// the target with `$target = self::resolve($base, $target);` and then try make it more relative
// by removing a duplicate query. But let's not do that automatically.
return $target;
}
if ($target->getAuthority() !== '' && $base->getAuthority() !== $target->getAuthority()) {
return $target->withScheme('');
}
// We must remove the path before removing the authority because if the path starts with two slashes, the URI
// would turn invalid. And we also cannot set a relative path before removing the authority, as that is also
// invalid.
$emptyPathUri = $target->withScheme('')->withPath('')->withUserInfo('')->withPort(null)->withHost('');
if ($base->getPath() !== $target->getPath()) {
return $emptyPathUri->withPath(self::getRelativePath($base, $target));
}
if ($base->getQuery() === $target->getQuery()) {
// Only the target fragment is left. And it must be returned even if base and target fragment are the same.
return $emptyPathUri->withQuery('');
}
// If the base URI has a query but the target has none, we cannot return an empty path reference as it would
// inherit the base query component when resolving.
if ($target->getQuery() === '') {
$segments = explode('/', $target->getPath());
$lastSegment = end($segments);
return $emptyPathUri->withPath($lastSegment === '' ? './' : $lastSegment);
}
return $emptyPathUri;
}
示例9: expandBase
/**
* Resolves the given relative or absolute $uri by appending it behind $this base URI
*
* The given $uri parameter can be either a relative or absolute URI and
* as such can not contain any URI template placeholders.
*
* As such, the outcome of this method represents a valid, absolute URI
* which will be returned as an instance implementing `UriInterface`.
*
* If the given $uri is a relative URI, it will simply be appended behind $base URI.
*
* If the given $uri is an absolute URI, it will simply be verified to
* be *below* the given $base URI.
*
* @param UriInterface $uri
* @param UriInterface $base
* @return UriInterface
* @throws \UnexpectedValueException
* @see Browser::resolve()
*/
public function expandBase(UriInterface $uri, UriInterface $base)
{
if ($uri->getScheme() !== '') {
if (strpos((string) $uri, (string) $base) !== 0) {
throw new \UnexpectedValueException('Invalid base, "' . $uri . '" does not appear to be below "' . $base . '"');
}
return $uri;
}
$uri = (string) $uri;
$base = (string) $base;
if ($uri !== '' && substr($base, -1) !== '/' && substr($uri, 0, 1) !== '?') {
$base .= '/';
}
if (isset($uri[0]) && $uri[0] === '/') {
$uri = substr($uri, 1);
}
return $this->uri($base . $uri);
}
示例10: isRelativePathReference
/**
* Whether the URI is a relative-path reference.
*
* A relative reference that does not begin with a slash character is termed a relative-path reference.
*
* @param UriInterface $uri
*
* @return bool
* @link https://tools.ietf.org/html/rfc3986#section-4.2
*/
public static function isRelativePathReference(UriInterface $uri)
{
return $uri->getScheme() === '' && $uri->getAuthority() === '' && (!isset($uri->getPath()[0]) || $uri->getPath()[0] !== '/');
}
示例11: join
/**
* {@inheritdoc}
*/
public function join(UriInterface $uriToJoin)
{
// other host
if ($uriToJoin->getScheme() !== '' || $uriToJoin->getHost() !== '') {
return clone $uriToJoin;
}
$uriToReturn = clone $this;
// current path.
if ($uriToJoin->getPath() === '' || $uriToJoin->getPath() === '.') {
return $uriToReturn;
}
$newPathItems = explode('/', $uriToReturn->path);
$pathItemToJoin = explode('/', $uriToJoin->getPath());
if (isset($pathItemToJoin[0])) {
array_pop($newPathItems);
}
$newPathItems = array_merge($newPathItems, $pathItemToJoin);
$pathItemsToReturn = [];
foreach ($newPathItems as $item) {
if ($item === '') {
$pathItemsToReturn = [$item];
} elseif ($item === '.') {
continue;
} elseif ($item === '..') {
array_pop($pathItemsToReturn);
} else {
array_push($pathItemsToReturn, $item);
}
}
if (isset($pathItemsToReturn[0]) && $pathItemsToReturn[0] !== '') {
array_unshift($pathItemsToReturn, '');
}
$uriToReturn->path = implode('/', $pathItemsToReturn);
$uriToReturn->query = $uriToJoin->getQuery();
$uriToReturn->fragment = $uriToJoin->getFragment();
return $uriToReturn;
}
示例12: validateUrl
/**
* Ensures that the url of the certificate is one belonging to AWS, and not
* just something from the amazonaws domain, which includes S3 buckets.
*
* @param UriInterface $uri
*
* @throws MessageValidatorException if the cert url is invalid
*/
private function validateUrl(UriInterface $uri)
{
// The cert URL must be https, a .pem, and match the following pattern.
$hostPattern = '/^sns\\.[a-zA-Z0-9\\-]{3,}\\.amazonaws\\.com(\\.cn)?$/';
if ($uri->getScheme() !== 'https' || substr($uri, -4) !== '.pem' || !preg_match($hostPattern, $uri->getHost())) {
throw new MessageValidatorException('The certificate is located ' . 'on an invalid domain.');
}
}
示例13: 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);
}
示例14: resolve
/**
* Resolve a base URI with a relative URI and return a new URI.
*
* @param UriInterface $base Base URI
* @param string|UriInterface $rel Relative URI
*
* @return UriInterface
* @link http://tools.ietf.org/html/rfc3986#section-5.2
*/
public static function resolve(UriInterface $base, $rel)
{
if (!$rel instanceof UriInterface) {
$rel = new self($rel);
}
if ((string) $rel === '') {
// we can simply return the same base URI instance for this same-document reference
return $base;
}
if ($rel->getScheme() != '') {
return $rel->withPath(self::removeDotSegments($rel->getPath()));
}
if ($rel->getAuthority() != '') {
$targetAuthority = $rel->getAuthority();
$targetPath = self::removeDotSegments($rel->getPath());
$targetQuery = $rel->getQuery();
} else {
$targetAuthority = $base->getAuthority();
if ($rel->getPath() === '') {
$targetPath = $base->getPath();
$targetQuery = $rel->getQuery() != '' ? $rel->getQuery() : $base->getQuery();
} else {
if ($rel->getPath()[0] === '/') {
$targetPath = $rel->getPath();
} else {
if ($targetAuthority != '' && $base->getPath() === '') {
$targetPath = '/' . $rel->getPath();
} else {
$lastSlashPos = strrpos($base->getPath(), '/');
if ($lastSlashPos === false) {
$targetPath = $rel->getPath();
} else {
$targetPath = substr($base->getPath(), 0, $lastSlashPos + 1) . $rel->getPath();
}
}
}
$targetPath = self::removeDotSegments($targetPath);
$targetQuery = $rel->getQuery();
}
}
return new self(self::createUriString($base->getScheme(), $targetAuthority, $targetPath, $targetQuery, $rel->getFragment()));
}
示例15: createAbsoulteUrl
/**
* @param $urlString
* @param UriInterface $originUrl
* @return UriInterface
*/
private function createAbsoulteUrl(UriInterface $uri, UriInterface $originUrl)
{
// @example href=""
if ((string) $uri == "" || strpos((string) $uri, "#") === 0) {
return $originUrl;
}
// @example href="?cat=1"
if (strpos((string) $uri, "?") === 0) {
return new Uri($originUrl->getScheme() . "://" . $originUrl->getHost() . $originUrl->getPath() . (string) $uri);
}
if ($uri->getScheme() === '') {
if ($uri->getQuery() !== '') {
$query = '?' . $uri->getQuery();
} else {
$query = '';
}
if ($uri->getHost() !== '') {
$uriString = $originUrl->getScheme() . '://' . $uri->getHost() . $uri->getPath() . $query;
} else {
if (strpos($uri->getPath(), '/') === 0) {
// absolute path
$uriString = $originUrl->getScheme() . '://' . $originUrl->getHost() . $uri->getPath() . $query;
} else {
// relative path
$pathParts = pathinfo($originUrl->getPath());
if (array_key_exists('dirname', $pathParts)) {
$dirname = $pathParts['dirname'];
if ($dirname != "/") {
$dirname .= "/";
}
} else {
$dirname = "/";
}
$uriString = $originUrl->getScheme() . '://' . $originUrl->getHost() . $dirname . $uri->getPath() . $query;
}
}
$resultUri = new Uri($uriString);
} else {
$resultUri = $uri;
}
return $resultUri;
}