本文整理汇总了PHP中Psr\Http\Message\UriInterface::getAuthority方法的典型用法代码示例。如果您正苦于以下问题:PHP UriInterface::getAuthority方法的具体用法?PHP UriInterface::getAuthority怎么用?PHP UriInterface::getAuthority使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\UriInterface
的用法示例。
在下文中一共展示了UriInterface::getAuthority方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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());
}
示例2: resolve
/**
* Resolve a base URI with a relative URI and return a new URI.
*
* @param UriInterface $base Base URI
* @param null|string|UriInterface $rel Relative URI
*
* @throws \InvalidArgumentException
*
* @return UriInterface
*/
public static function resolve(UriInterface $base, $rel = null)
{
if ($rel === null || $rel === '') {
return $base;
}
if (!$rel instanceof UriInterface) {
$rel = new self($rel);
}
// Return the relative uri as-is if it has a scheme.
if ($rel->getScheme()) {
return $rel->withPath(static::removeDotSegments($rel->getPath()));
}
$relParts = ['scheme' => $rel->getScheme(), 'authority' => $rel->getAuthority(), 'path' => $rel->getPath(), 'query' => $rel->getQuery(), 'fragment' => $rel->getFragment()];
$parts = ['scheme' => $base->getScheme(), 'authority' => $base->getAuthority(), 'path' => $base->getPath(), 'query' => $base->getQuery(), 'fragment' => $base->getFragment()];
if (!empty($relParts['path'])) {
if (strpos($relParts['path'], '/') === 0) {
$parts['path'] = self::removeDotSegments($relParts['path']);
$parts['query'] = $relParts['query'];
$parts['fragment'] = $relParts['fragment'];
} 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 new self(static::createUriString($parts['scheme'], $parts['authority'], $parts['path'], $parts['query'], $parts['fragment']));
}
示例3: getRelativePath
private static function getRelativePath(UriInterface $base, UriInterface $target)
{
$sourceSegments = explode('/', $base->getPath());
$targetSegments = explode('/', $target->getPath());
array_pop($sourceSegments);
$targetLastSegment = array_pop($targetSegments);
foreach ($sourceSegments as $i => $segment) {
if (isset($targetSegments[$i]) && $segment === $targetSegments[$i]) {
unset($sourceSegments[$i], $targetSegments[$i]);
} else {
break;
}
}
$targetSegments[] = $targetLastSegment;
$relativePath = str_repeat('../', count($sourceSegments)) . implode('/', $targetSegments);
// A reference to am empty last segment or an empty first sub-segment must be prefixed with "./".
// This also applies to a segment with a colon character (e.g., "file:colon") that cannot be used
// as the first segment of a relative-path reference, as it would be mistaken for a scheme name.
if ('' === $relativePath || false !== strpos(explode('/', $relativePath, 2)[0], ':')) {
$relativePath = "./{$relativePath}";
} elseif ('/' === $relativePath[0]) {
if ($base->getAuthority() != '' && $base->getPath() === '') {
// In this case an extra slash is added by resolve() automatically. So we must not add one here.
$relativePath = ".{$relativePath}";
} else {
$relativePath = "./{$relativePath}";
}
}
return $relativePath;
}
示例4: 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] !== '/');
}
示例5: 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()));
}
示例6: runMatches
protected function runMatches(UriInterface $uri)
{
return $uri->getAuthority() == $this->expected;
}
示例7: s3MVC_UriToString
/**
*
* Converts a uri object to a string in the format <scheme>://<server_address>/<path>?<query_string>#<fragment>
*
* @param \Psr\Http\Message\UriInterface $uri uri object to be converted to a string
*
* @return string the string represntation of the uri object.
* Eg. http://someserver.com/controller/action
*/
function s3MVC_UriToString(\Psr\Http\Message\UriInterface $uri)
{
$scheme = $uri->getScheme();
$authority = $uri->getAuthority();
$basePath = s3MVC_GetBaseUrlPath();
$path = $uri->getPath();
$query = $uri->getQuery();
$fragment = $uri->getFragment();
$path = $basePath . '/' . ltrim($path, '/');
return ($scheme ? $scheme . ':' : '') . ($authority ? '//' . $authority : '') . $path . ($query ? '?' . $query : '') . ($fragment ? '#' . $fragment : '');
}