本文整理汇总了PHP中GuzzleHttp\Psr7\uri_for函数的典型用法代码示例。如果您正苦于以下问题:PHP uri_for函数的具体用法?PHP uri_for怎么用?PHP uri_for使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了uri_for函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_It_Gets_Public_Uri
public function test_It_Gets_Public_Uri()
{
$this->client->getConfig('base_uri')->shouldBeCalled()->willReturn(uri_for('myopenstack.org:9000/tenantId'));
$this->object->containerName = 'foo';
$this->object->name = 'bar';
$this->assertEquals(uri_for('myopenstack.org:9000/tenantId/foo/bar'), $this->object->getPublicUri());
}
示例2: createUri
/**
* {@inheritdoc}
*/
public function createUri($uri) : UriInterface
{
try {
return uri_for($uri);
} catch (Exception $exception) {
throw new DomainException($exception->getMessage(), $exception->getCode(), $exception);
}
}
示例3: test_it_retrieves_base_http_url
public function test_it_retrieves_base_http_url()
{
$returnedUri = uri_for('http://foo.com');
$this->client->getConfig('base_uri')->shouldBeCalled()->willReturn($returnedUri);
$uri = $this->operator->testBaseUri();
$this->assertInstanceOf(Uri::class, $uri);
$this->assertEquals($returnedUri, $uri);
}
示例4: buildUriWithQuery
/**
* @param string $uri
* @param array $query
* @return UriInterface
*/
public function buildUriWithQuery($uri, array $query)
{
// @todo fix this hack. when using build_query booleans are converted to
// 1 or 0 which the API does not accept. this casts bools to their
// string representation
$query = array_filter($query);
foreach ($query as $k => &$v) {
if (is_bool($v)) {
$v = $v ? 'true' : 'false';
}
}
return Psr7\uri_for($uri)->withQuery(Psr7\build_query($query));
}
示例5: parse
/**
* Parses a URL into an associative array of Amazon S3 data including:
*
* - bucket: The Amazon S3 bucket (null if none)
* - key: The Amazon S3 key (null if none)
* - path_style: Set to true if using path style, or false if not
* - region: Set to a string if a non-class endpoint is used or null.
*
* @param string|UriInterface $uri
*
* @return array
* @throws \InvalidArgumentException
*/
public function parse($uri)
{
$url = Psr7\uri_for($uri);
if (!$url->getHost()) {
throw new \InvalidArgumentException('No hostname found in URI: ' . $uri);
}
if (!preg_match($this->pattern, $url->getHost(), $matches)) {
return $this->parseCustomEndpoint($url);
}
// Parse the URI based on the matched format (path / virtual)
$result = empty($matches[1]) ? $this->parsePathStyle($url) : $this->parseVirtualHosted($url, $matches);
// Add the region if one was found and not the classic endpoint
$result['region'] = $matches[2] == 'amazonaws' ? null : $matches[2];
return $result;
}
示例6: makeStack
public function makeStack(CurlHandler $curl, HandlerStack $stack)
{
$stack->setHandler($curl);
$stack->push(function (callable $handler) {
return function (RequestInterface $request, array $options) use($handler) {
$method = $request->getMethod();
$uri = '/' . trim($request->getUri()->getPath(), '/');
$qs = $request->getUri()->getQuery();
if ($qs) {
$qs = '?' . $qs;
}
$header = $this->getAuthenticationHeader($method, $uri);
$request = $request->withHeader('Authentication', $header);
$request = $request->withUri(Psr7\uri_for(static::BASE_URL . $uri . $qs));
return $handler($request, $options);
};
});
return $stack;
}
示例7: get
public static function get($path, $query = [])
{
if (!isset(self::$guzzle)) {
self::initUsingConfigFile();
}
if (is_array($query)) {
$query = self::weedOut($query);
$query = http_build_query($query, null, '&', PHP_QUERY_RFC3986);
$query = preg_replace('/%5[bB]\\d+%5[dD]=/', '=', $query);
}
$response = self::$guzzle->get($path, ['query' => $query]);
switch ($response->getStatusCode()) {
case 200:
return json_decode($response->getBody(), true);
case 404:
return null;
default:
$uri = Psr7\Uri::resolve(Psr7\uri_for(self::$guzzle->getConfig('base_uri')), $path);
$uri = $uri->withQuery($query);
throw new ServerException($response->getStatusCode() . " " . $response->getReasonPhrase() . ". URI: " . $uri);
}
}
示例8: testValidatesUri
/**
* @expectedException \InvalidArgumentException
*/
public function testValidatesUri()
{
Psr7\uri_for(array());
}
示例9: downloadObject
/**
* @param array $args
*/
public function downloadObject(array $args = [])
{
$args += ['bucket' => null, 'object' => null, 'generation' => null];
$requestOptions = array_intersect_key($args, ['httpOptions' => null, 'retries' => null]);
$uri = $this->expandUri(self::DOWNLOAD_URI, ['bucket' => $args['bucket'], 'object' => $args['object'], 'query' => ['generation' => $args['generation'], 'alt' => 'media']]);
return $this->requestWrapper->send(new Request('GET', Psr7\uri_for($uri)), $requestOptions)->getBody();
}
示例10: test_it_adds_paths
public function test_it_adds_paths()
{
$uri = Utils::addPaths(uri_for('http://openstack.org/foo'), 'bar', 'baz', '1', '2');
$this->assertInstanceOf(Uri::class, $uri);
$this->assertEquals(uri_for('http://openstack.org/foo/bar/baz/1/2'), $uri);
}
示例11: appendPath
public static function appendPath(UriInterface $uri, $path) : UriInterface
{
return uri_for(rtrim((string) $uri, '/') . '/' . $path);
}
示例12: withRootUrl
public function withRootUrl($rootUrl)
{
$instance = clone $this;
$instance->defaultRequest = $instance->defaultRequest->withUri(GuzzlePsr7\uri_for($rootUrl));
return $instance;
}
示例13: testCanBeUrlObject
public function testCanBeUrlObject()
{
$config = array_merge($this->minimal, ['authorizationUri' => Psr7\uri_for('https://another/uri')]);
$o = new OAuth2($config);
$this->assertEquals('/uri', $o->buildFullAuthorizationUri()->getPath());
}
示例14: createUrl
/**
* Create a Guzzle url for the given URI.
*
* @param string $uri
*
* @return Url
*/
protected function createUrl($uri)
{
return Psr7\uri_for($uri);
}
示例15: testValidatesUri
/**
* @expectedException \InvalidArgumentException
*/
public function testValidatesUri()
{
Psr7\uri_for([]);
}