예제 #1
1
 /**
  * This method adds the current parameter to the specified REST API request.
  *
  * @param \GuzzleHttp\Psr7\Request $request
  * @return Request
  */
 public function apply(Request $request)
 {
     $queryString = $request->getUri()->getQuery();
     $queryParts = \GuzzleHttp\Psr7\parse_query($queryString);
     $queryParts[$this->name] = $this->value;
     $queryString = \GuzzleHttp\Psr7\build_query($queryParts);
     return $request->withUri($request->getUri()->withQuery($queryString));
 }
예제 #2
0
 /**
  * @param Client $client
  */
 protected function copyClientDefaults(Client $client)
 {
     $this->request->withUri(new Uri($client->getConfig('base_uri') . $this->request->getUri()));
     foreach ($client->getConfig('headers') as $header => $value) {
         $this->request->withAddedHeader($header, $value);
     }
 }
예제 #3
0
 public function testQueryParser()
 {
     $endpoint = $this->getEndpoint();
     $handler = $this->getHandler($endpoint);
     $request = new Request('GET', new Uri($endpoint->url()));
     $uri = $request->getUri()->withQuery('abc=123&def=456&ghi=789');
     $query_array = $handler->queryAsArray($request->withUri($uri));
     $this->assertEquals(3, count($query_array));
     $this->assertArrayHasKey('abc', $query_array);
     $this->assertArrayHasKey('def', $query_array);
     $this->assertArrayHasKey('ghi', $query_array);
     $uri = $request->getUri()->withQuery('abc=123&&ghi=789');
     $query_array = $handler->queryAsArray($request->withUri($uri));
     $this->assertEquals(2, count($query_array));
     $this->assertArrayHasKey('abc', $query_array);
     $this->assertArrayHasKey('ghi', $query_array);
 }
예제 #4
0
 /**
  * Creates a request.
  *
  * @param  string $verb
  * @param  string $path
  * @param  array  $parameters
  *
  * @return Request
  */
 protected function createRequest($verb, $path, $parameters = [])
 {
     if (isset($parameters['file'])) {
         $this->queueResourceAs('file', \GuzzleHttp\Psr7\stream_for($parameters['file']));
         unset($parameters['file']);
     }
     $request = new Request($verb, $this->getUrlFromPath($path), $this->getHeaders());
     return $request->withUri($request->getUri()->withQuery(http_build_query($parameters)));
 }
예제 #5
0
 /**
  * Get all of the received requests.
  *
  * @throws \RuntimeException
  * @return ResponseInterface[]
  *
  */
 public static function received()
 {
     if (!self::$started) {
         return [];
     }
     $response = self::getClient()->request('GET', 'guzzle-server/requests');
     $data = json_decode($response->getBody(), true);
     return array_map(function ($message) {
         $uri = $message['uri'];
         if (isset($message['query_string'])) {
             $uri .= '?' . $message['query_string'];
         }
         $response = new Psr7\Request($message['http_method'], $uri, $message['headers'], $message['body'], $message['version']);
         return $response->withUri($response->getUri()->withScheme('http')->withHost($response->getHeaderLine('host')));
     }, $data);
 }
 private function meRequest($accessToken, array $fields)
 {
     $request = new Request('GET', FacebookApi::GRAPH_API_ME_URL);
     $query = $request->getUri();
     $query = Uri::withQueryValue($query, 'access_token', $accessToken);
     if (!empty($fields)) {
         $query = Uri::withQueryValue($query, 'fields', implode(',', $fields));
     }
     return $request->withUri($query);
 }
예제 #7
0
 public function testOverridesHostWithUri()
 {
     $r = new Request('GET', 'http://foo.com/baz?bar=bam');
     $this->assertEquals(['Host' => ['foo.com']], $r->getHeaders());
     $r2 = $r->withUri(new Uri('http://www.baz.com/bar'));
     $this->assertEquals('www.baz.com', $r2->getHeaderLine('Host'));
 }