public function testConvertsPlusSymbolsToSpacesByDefault() { $query = Query::fromString('var=foo+bar', true); $this->assertEquals('foo bar', $query->get('var')); }
public function testQueryStringsAllowDecodingEncodingCompletelyDisabled() { $q = Query::fromString('foo=bar%2Fbaz&bam=boo boo!', false); $this->assertEquals('foo=bar%2Fbaz&bam=boo boo!', (string) $q); }
/** * 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)); } }