本文整理汇总了PHP中Psr\Http\Message\UriInterface::getFragment方法的典型用法代码示例。如果您正苦于以下问题:PHP UriInterface::getFragment方法的具体用法?PHP UriInterface::getFragment怎么用?PHP UriInterface::getFragment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\UriInterface
的用法示例。
在下文中一共展示了UriInterface::getFragment方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例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: formatFragment
/**
* Format a URI Fragment component according to the Formatter properties
*
* @param UriInterface|Uri $uri
*
* @return string
*/
protected function formatFragment($uri)
{
$fragment = $uri->getFragment();
if ($this->preserveFragment || '' != $fragment) {
$fragment = '#' . $fragment;
}
return $fragment;
}
示例4: 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;
}
示例5: resolve
/**
* Converts the relative URI into a new URI that is resolved against the base URI.
*
* @param UriInterface $base Base URI
* @param UriInterface $rel Relative URI
*
* @return UriInterface
* @link http://tools.ietf.org/html/rfc3986#section-5.2
*/
public static function resolve(UriInterface $base, UriInterface $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 Uri(Uri::composeComponents($base->getScheme(), $targetAuthority, $targetPath, $targetQuery, $rel->getFragment()));
}
示例6: 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 : '');
}
示例7: formatUri
/**
* Format a Interfaces\Schemes\Uri according to the Formatter properties
*
* @param Uri|UriInterface $uri
*
* @return string
*/
protected function formatUri($uri)
{
$scheme = $uri->getScheme();
if ('' !== $scheme) {
$scheme .= ':';
}
$query = $this->formatUriPart(new Query($uri->getQuery()));
if ('' !== $query) {
$query = '?' . $query;
}
$fragment = $uri->getFragment();
if ('' !== $fragment) {
$fragment = '#' . $fragment;
}
$auth = $this->formatAuthority($uri);
return $scheme . $auth . $this->formatPath($uri->getPath(), $auth) . $query . $fragment;
}
示例8: 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;
}
示例9: runMatches
protected function runMatches(UriInterface $uri)
{
return $uri->getFragment() == $this->expected;
}