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()); }
/** * {@inheritdoc} */ public function createUri($uri) : UriInterface { try { return uri_for($uri); } catch (Exception $exception) { throw new DomainException($exception->getMessage(), $exception->getCode(), $exception); } }
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); }
/** * @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)); }
/** * 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; }
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; }
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); } }
/** * @expectedException \InvalidArgumentException */ public function testValidatesUri() { Psr7\uri_for(array()); }
/** * @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(); }
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); }
public static function appendPath(UriInterface $uri, $path) : UriInterface { return uri_for(rtrim((string) $uri, '/') . '/' . $path); }
public function withRootUrl($rootUrl) { $instance = clone $this; $instance->defaultRequest = $instance->defaultRequest->withUri(GuzzlePsr7\uri_for($rootUrl)); return $instance; }
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()); }
/** * Create a Guzzle url for the given URI. * * @param string $uri * * @return Url */ protected function createUrl($uri) { return Psr7\uri_for($uri); }
/** * @expectedException \InvalidArgumentException */ public function testValidatesUri() { Psr7\uri_for([]); }
private function buildUri($uri, array $config) { if (!isset($config['base_uri'])) { return $uri instanceof UriInterface ? $uri : new Psr7\Uri($uri); } return Psr7\Uri::resolve(Psr7\uri_for($config['base_uri']), $uri); }
/** * {@inheritdoc} */ public function createUri($uri) { return Psr7\uri_for($uri); }
public function __construct(HttpClient $httpClient = null, Manager $manager = null) { $this->httpClient = $httpClient ?: new HttpClient(); $this->manager = $manager ?: new Manager(); $this->baseUri = Psr7\uri_for('http://srazy.info'); }
private function fixUri(Step $step, $uri) { if (!$step->getEndpoint()) { return $uri; } return Psr7\Uri::resolve(Psr7\uri_for($step->getEndpoint()), $uri); }
/** * @param Service $api Service API description * @param string $endpoint Endpoint to connect to */ public function __construct(Service $api, $endpoint) { $this->api = $api; $this->endpoint = Psr7\uri_for($endpoint); }
private function buildUri($uri, array $config) { // for BC we accept null which would otherwise fail in uri_for $uri = Psr7\uri_for($uri === null ? '' : $uri); if (isset($config['base_uri'])) { $uri = Psr7\Uri::resolve(Psr7\uri_for($config['base_uri']), $uri); } return $uri->getScheme() === '' ? $uri->withScheme('http') : $uri; }
/** * @todo handle uri as array * * @param string $uri * * @return null|UriInterface */ private function coerceUri($uri) { if (is_null($uri)) { return; } return Psr7\uri_for($uri); }
/** * @param string $path * * @return \Psr\Http\Message\UriInterface */ public function buildUri($path) { return Psr7\Uri::resolve(Psr7\uri_for($this->baseUri), $path); }
/** * Add an unlimited list of paths to a given URI. * * @param UriInterface $uri * @param ...$paths * * @return UriInterface */ public static function addPaths(UriInterface $uri, ...$paths) { return uri_for(rtrim((string) $uri, '/') . '/' . implode('/', $paths)); }