Example #1
0
 public function testCanUseUrlWithCustomQuery()
 {
     $client = new Client();
     $url = Url::fromString('http://foo.com/bar');
     $query = new Query(['baz' => '123%20']);
     $query->setEncodingType(false);
     $url->setQuery($query);
     $r = $client->createRequest('GET', $url);
     $this->assertEquals('http://foo.com/bar?baz=123%20', $r->getUrl());
 }
 public function testCanSpecifyQueryAggregator()
 {
     $b = new PostBody();
     $b->setField('foo', ['baz', 'bar']);
     $this->assertEquals('foo%5B0%5D=baz&foo%5B1%5D=bar', (string) $b);
     $b = new PostBody();
     $b->setField('foo', ['baz', 'bar']);
     $agg = Query::duplicateAggregator();
     $b->setAggregator($agg);
     $this->assertEquals('foo=baz&foo=bar', (string) $b);
 }
 /**
  * @ticket https://github.com/guzzle/guzzle/issues/706
  */
 public function testDoesNotApplyPostBodyRightAway()
 {
     $request = (new MessageFactory())->createRequest('POST', 'http://f.cn', ['body' => ['foo' => ['bar', 'baz']]]);
     $this->assertEquals('', $request->getHeader('Content-Type'));
     $this->assertEquals('', $request->getHeader('Content-Length'));
     $request->getBody()->setAggregator(Query::duplicateAggregator());
     $request->getBody()->applyRequestHeaders($request);
     $this->assertEquals('foo=bar&foo=baz', $request->getBody());
 }
Example #4
0
 public function testQueryStringsAllowDecodingEncodingCompletelyDisabled()
 {
     $q = Query::fromString('foo=bar%2Fbaz&bam=boo boo!', false);
     $this->assertEquals('foo=bar%2Fbaz&bam=boo boo!', (string) $q);
 }
 public function testConvertsPlusSymbolsToSpacesByDefault()
 {
     $query = Query::fromString('var=foo+bar', true);
     $this->assertEquals('foo bar', $query->get('var'));
 }
Example #6
0
 /**
  * Get the aggregator used to join multi-valued field parameters
  *
  * @return callable
  */
 protected final function getAggregator()
 {
     if (!$this->aggregator) {
         $this->aggregator = Query::phpAggregator();
     }
     return $this->aggregator;
 }
Example #7
0
 /**
  * Set the query part of the URL.
  *
  * You may provide a query string as a string and pass $rawString as true
  * to provide a query string that is not parsed until a call to getQuery()
  * is made. Setting a raw query string will still encode invalid characters
  * in a query string.
  *
  * @param Query|string|array $query Query string value to set. Can
  *     be a string that will be parsed into a Query object, an array
  *     of key value pairs, or a Query object.
  * @param bool $rawString Set to true when providing a raw query string.
  *
  * @throws \InvalidArgumentException
  */
 public function setQuery($query, $rawString = false)
 {
     if ($query instanceof Query) {
         $this->query = $query;
     } elseif (is_string($query)) {
         if (!$rawString) {
             $this->query = Query::fromString($query);
         } else {
             // Ensure the query does not have illegal characters.
             $this->query = preg_replace_callback(self::$queryPattern, [__CLASS__, 'encodeMatch'], $query);
         }
     } elseif (is_array($query)) {
         $this->query = new Query($query);
     } else {
         throw new \InvalidArgumentException('Query must be a Query, ' . 'array, or string. Got ' . Core::describeType($query));
     }
 }