コード例 #1
0
ファイル: ObjectTest.php プロジェクト: kunalp/openstack
 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
0
 /**
  * {@inheritdoc}
  */
 public function createUri($uri) : UriInterface
 {
     try {
         return uri_for($uri);
     } catch (Exception $exception) {
         throw new DomainException($exception->getMessage(), $exception->getCode(), $exception);
     }
 }
コード例 #3
0
ファイル: OperatorTest.php プロジェクト: kunalp/openstack
 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
0
 /**
  * @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
0
 /**
  * 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
0
 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
0
 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
0
ファイル: FunctionsTest.php プロジェクト: kirill-konshin/psr7
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testValidatesUri()
 {
     Psr7\uri_for(array());
 }
コード例 #9
0
 /**
  * @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
0
ファイル: UtilsTest.php プロジェクト: kunalp/openstack
 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
0
ファイル: Utils.php プロジェクト: php-opencloud/common
 public static function appendPath(UriInterface $uri, $path) : UriInterface
 {
     return uri_for(rtrim((string) $uri, '/') . '/' . $path);
 }
コード例 #12
0
ファイル: HalClient.php プロジェクト: jsor/hal-client
 public function withRootUrl($rootUrl)
 {
     $instance = clone $this;
     $instance->defaultRequest = $instance->defaultRequest->withUri(GuzzlePsr7\uri_for($rootUrl));
     return $instance;
 }
コード例 #13
0
 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
0
 /**
  * Create a Guzzle url for the given URI.
  *
  * @param string $uri
  *
  * @return Url
  */
 protected function createUrl($uri)
 {
     return Psr7\uri_for($uri);
 }
コード例 #15
0
ファイル: FunctionsTest.php プロジェクト: xcorlett/psr7
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testValidatesUri()
 {
     Psr7\uri_for([]);
 }
コード例 #16
0
ファイル: Client.php プロジェクト: Sebascii/guzzle
 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);
 }
コード例 #17
0
ファイル: GuzzleUriFactory.php プロジェクト: php-http/message
 /**
  * {@inheritdoc}
  */
 public function createUri($uri)
 {
     return Psr7\uri_for($uri);
 }
コード例 #18
0
ファイル: Client.php プロジェクト: webuni/srazy-api-client
 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');
 }
コード例 #19
0
ファイル: RequestFactory.php プロジェクト: stof/player
 private function fixUri(Step $step, $uri)
 {
     if (!$step->getEndpoint()) {
         return $uri;
     }
     return Psr7\Uri::resolve(Psr7\uri_for($step->getEndpoint()), $uri);
 }
コード例 #20
0
 /**
  * @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);
 }
コード例 #21
0
ファイル: Client.php プロジェクト: sgtsaughter/d8portfolio
 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;
 }
コード例 #22
0
ファイル: OAuth2.php プロジェクト: branJakJak/dienSiSystem
 /**
  * @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);
 }
コード例 #23
0
ファイル: Http.php プロジェクト: lichunqiang/easemob
 /**
  * @param string $path
  *
  * @return \Psr\Http\Message\UriInterface
  */
 public function buildUri($path)
 {
     return Psr7\Uri::resolve(Psr7\uri_for($this->baseUri), $path);
 }
コード例 #24
0
ファイル: Utils.php プロジェクト: alewitt/openstack
 /**
  * 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));
 }