本文整理汇总了PHP中GuzzleHttp\Psr7\Uri::getPath方法的典型用法代码示例。如果您正苦于以下问题:PHP Uri::getPath方法的具体用法?PHP Uri::getPath怎么用?PHP Uri::getPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Psr7\Uri
的用法示例。
在下文中一共展示了Uri::getPath方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
public function register(Container $pimple)
{
// File extensions used to determine whether a URI points to an asset
// or an HTML file.
$pimple['html_extensions'] = static::$html_extensions;
$pimple['asset_extensions'] = static::$asset_extensions;
// Matches any URI we think points to an HTML page.
$pimple['matcher.html'] = function () use($pimple) {
return Matcher::all()->pathExtensionIs($pimple['html_extensions']);
};
// Matches any URI we think points to an asset file.
$pimple['matcher.asset'] = function () use($pimple) {
return Matcher::all()->pathExtensionIs($pimple['asset_extensions']);
};
// Matches any URI that is considered "in scope."
$pimple['matcher.internal'] = function () use($pimple) {
$uri = new Uri($pimple['base_url']);
return Matcher::all()->schemeIs($uri->getScheme())->hostIs($uri->getHost())->pathMatches('~^' . preg_quote($uri->getPath(), '~') . '~');
};
// Matches any URI that is both internal and HTML.
$pimple['matcher.internal_html'] = function () use($pimple) {
return Matcher::all()->add($pimple['matcher.internal'])->add($pimple['matcher.html']);
};
// Matches any URI that is both internal and an asset.
$pimple['matcher.internal_asset'] = function () use($pimple) {
return Matcher::all()->add($pimple['matcher.internal'])->add($pimple['matcher.asset']);
};
}
示例2: withBaseUri
/**
* @param string|UriInterface $baseUri
* @return ApiUri
* @throws \InvalidArgumentException
*/
public function withBaseUri($baseUri)
{
if (empty($baseUri)) {
throw new \InvalidArgumentException('You must provide a non-empty string or PSR-7 UserInterface');
} elseif (is_string($baseUri)) {
$baseUri = new Psr7\Uri($baseUri);
} elseif (!$baseUri instanceof UriInterface) {
throw new \InvalidArgumentException('Invalid format provided; should either be a string or PSR-7 UriInterface');
}
if (!in_array($baseUri->getScheme(), ['http', 'https'])) {
throw new \InvalidArgumentException('Only http & https schemes are allowed');
}
// always store the base URI with a final /
if (!preg_match('{/$}', $baseUri->getPath())) {
$baseUri = $baseUri->withPath($baseUri->getPath() . '/');
}
/** @var ApiUri $new */
if ('' === (string) $this) {
$new = new static($baseUri);
} else {
$new = clone $this;
}
$new->baseUri = $baseUri;
return $new;
}
示例3: testAllowsFalseyUrlParts
public function testAllowsFalseyUrlParts()
{
$url = new Uri('http://a:1/0?0#0');
$this->assertSame('a', $url->getHost());
$this->assertEquals(1, $url->getPort());
$this->assertSame('/0', $url->getPath());
$this->assertEquals('0', (string) $url->getQuery());
$this->assertSame('0', $url->getFragment());
$this->assertEquals('http://a:1/0?0#0', (string) $url);
$url = new Uri('');
$this->assertSame('', (string) $url);
$url = new Uri('0');
$this->assertSame('/0', (string) $url);
}
示例4: assertUriEquals
protected function assertUriEquals($expectedUri, $actualUri)
{
if (is_string($expectedUri)) {
$expectedUri = new Psr7\Uri($expectedUri);
}
if (is_string($actualUri)) {
$actualUri = new Psr7\Uri($actualUri);
}
$this->assertEquals($expectedUri->getScheme(), $actualUri->getScheme());
$this->assertEquals($expectedUri->getPort(), $actualUri->getPort());
$this->assertEquals($expectedUri->getHost(), $actualUri->getHost());
$this->assertEquals($expectedUri->getPath(), $actualUri->getPath());
$expectedQueryParts = Psr7\parse_query($expectedUri->getQuery());
$actualQueryParts = Psr7\parse_query($actualUri->getQuery());
$this->assertEquals($expectedQueryParts, $actualQueryParts);
}
示例5: baseString
/**
* Generate a base string for a HMAC-SHA1 signature
* based on the given a url, method, and any parameters.
*
* @param Url $url
* @param string $method
* @param array $parameters
*
* @return string
*/
protected function baseString(Uri $url, $method = 'POST', array $parameters = array())
{
$baseString = rawurlencode($method) . '&';
$schemeHostPath = Uri::fromParts(array('scheme' => $url->getScheme(), 'host' => $url->getHost(), 'path' => $url->getPath()));
$baseString .= rawurlencode($schemeHostPath) . '&';
$data = array();
parse_str($url->getQuery(), $query);
$data = array_merge($query, $parameters);
// normalize data key/values
array_walk_recursive($data, function (&$key, &$value) {
$key = rawurlencode(rawurldecode($key));
$value = rawurlencode(rawurldecode($value));
});
ksort($data);
$baseString .= $this->queryStringFromData($data);
return $baseString;
}
示例6: retrieveUri
/**
* Retrieve /path?query#fragment part of URL
* @param $url
* @return string
*/
public static function retrieveUri($url)
{
$uri = new Psr7Uri($url);
return (string) (new Psr7Uri())->withPath($uri->getPath())->withQuery($uri->getQuery())->withFragment($uri->getFragment());
}
示例7: testDefaultReturnValuesOfGetters
public function testDefaultReturnValuesOfGetters()
{
$uri = new Uri();
$this->assertSame('', $uri->getScheme());
$this->assertSame('', $uri->getAuthority());
$this->assertSame('', $uri->getUserInfo());
$this->assertSame('', $uri->getHost());
$this->assertNull($uri->getPort());
$this->assertSame('', $uri->getPath());
$this->assertSame('', $uri->getQuery());
$this->assertSame('', $uri->getFragment());
}
示例8: handleLocation
/**
* Handle 'Location' header with URI of created/updated resource.
*
* @param $location
*
* @return array
*/
protected function handleLocation($location)
{
$uri = new Uri($location);
$path = trim($uri->getPath(), '/');
$response = $this->makeRequest($path, self::METHOD_GET);
return $this->response_parser->parseResponse($response);
}
示例9: testDeletePatch
public function testDeletePatch()
{
$queryParams = ['test_query_key' => 'test_query_value'];
$url = new Uri('/test1/test2');
$queryStr = http_build_query($queryParams);
$url->withQuery($queryStr);
$reqHeaders = ['Content-Type' => 'application/json', 'X-Test-Header' => 'test_header_value'];
$reqOpts = ['headers' => $reqHeaders, 'query' => $queryParams];
$expRespData = ['value' => true];
$expResp = new Response(200, ['Content-Type' => 'application/json'], json_encode($expRespData));
$httpClient = $this->getMockHttpClient();
$httpClient->expects($this->once())->method('request')->with($this->equalTo('DELETE'), $this->equalTo($url->getPath()), $this->equalTo($reqOpts))->will($this->returnValue($expResp));
$client = new Client();
$client->setHttpClient($httpClient);
$data = $client->delete($url->getPath(), $queryParams, $reqHeaders);
$this->assertSame($expRespData, $data);
$this->assertSame($expResp, $client->getResponse());
}