本文整理汇总了PHP中Psr\Http\Message\UriInterface::withPath方法的典型用法代码示例。如果您正苦于以下问题:PHP UriInterface::withPath方法的具体用法?PHP UriInterface::withPath怎么用?PHP UriInterface::withPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\UriInterface
的用法示例。
在下文中一共展示了UriInterface::withPath方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute(Command $command, string $grammarPath) : SimpleXMLElement
{
$uri = $this->uri->withPath($grammarPath);
$response = $this->httpClient->sendRequest($this->buildRequest($command, $uri));
if (200 !== (int) $response->getStatusCode()) {
throw InvalidResponseException::fromUnsuccessfulResponse($response);
}
$previousValue = libxml_use_internal_errors(true);
$xml = simplexml_load_string((string) $response->getBody());
libxml_use_internal_errors($previousValue);
if (false === $xml) {
throw InvalidResponseException::fromXmlError(libxml_get_last_error());
}
return $xml;
}
示例2: setBase
public function setBase(UriInterface $uri)
{
$base = (string) $uri->withPath('')->withQuery('')->withFragment('');
if ($base and $base !== $this->base) {
$this->base = $base;
}
}
示例3: updateBaseUri
public function updateBaseUri(UriInterface $uri)
{
$base = (string) $uri->withPath('')->withQuery('')->withFragment('');
$oldBase = (string) $this->getClient()->getConfig('base_uri');
if ($base and $base !== $oldBase) {
$this->client = new Client(['base_uri' => $base]);
}
}
示例4: forward_aliases
/**
* @param UriInterface $uri
* @return UriInterface
* @throws \ErrorException
*/
protected function forward_aliases(UriInterface $uri)
{
// strip beginning /
$path = substr($uri->getPath(), 1);
$aliases = $this->db->conn()->prepare(<<<SQL
SELECT `alias_go`, `alias_forward_to`
FROM `{$this->db->getPrefix()}aliases`
WHERE `alias_active` = 1 AND `alias_go` = ?
SQL
);
$aliases->execute(array($path));
$aliases = $aliases->fetchAll(\PDO::FETCH_ASSOC);
foreach ($aliases as $alias) {
if ($path == $alias['alias_go']) {
$path = $alias['alias_forward_to'];
}
}
return $uri->withPath('/' . $path);
}
示例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: decodeUnreservedCharacters
private static function decodeUnreservedCharacters(UriInterface $uri)
{
$regex = '/%(?:2D|2E|5F|7E|3[0-9]|[46][1-9A-F]|[57][0-9A])/i';
$callback = function (array $match) {
return rawurldecode($match[0]);
};
return $uri->withPath(preg_replace_callback($regex, $callback, $uri->getPath()))->withQuery(preg_replace_callback($regex, $callback, $uri->getQuery()));
}
示例7: resolve
/**
* Resolve a base URI with a relative URI and return a new URI.
*
* @param UriInterface $base Base URI
* @param UriInterface $rel Relative URI
*
* @return UriInterface
*/
public static function resolve(UriInterface $base, UriInterface $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['authority'])) {
$parts['authority'] = $relParts['authority'];
$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['authority']) && 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']) {
$parts['fragment'] = $relParts['fragment'];
}
return new Uri(static::createUriString($parts['scheme'], $parts['authority'], $parts['path'], $parts['query'], $parts['fragment']));
}
示例8: buildRequestUri
/**
* Create a complete API Uri from the Base Uri, path and query parameters.
*
* Example:
* Given a base uri that equal http://domain.tld
* Given the following parameters /pets/{id}, ['id' => 1], ['foo' => 'bar']
* Then the Uri will equal to http://domain.tld/pets/1?foo=bar
*
* @param string $pathTemplate A template path
* @param array $pathParameters Path parameters
* @param array $queryParameters Query parameters
*
* @return UriInterface
*/
private function buildRequestUri($pathTemplate, array $pathParameters, array $queryParameters)
{
$path = $this->uriTemplate->expand($pathTemplate, $pathParameters);
$query = http_build_query($queryParameters);
return $this->baseUri->withPath($path)->withQuery($query);
}
示例9: withPath
/**
* Create an UriInterface with the request URI information from `$server`. It uses `$server['REQUEST_URI']` for
* this information.
*
* @param UriInterface $uri
* @param array $server
*
* @return UriInterface
*/
private function withPath(UriInterface $uri, array $server) : UriInterface
{
if (isset($server['REQUEST_URI'])) {
return $uri->withPath(\current(\explode('?', $server['REQUEST_URI'], 2)));
}
return $uri;
}