Phly\Http\Uri::withQuery PHP Method

withQuery() public method

public withQuery ( $query )
    public function withQuery($query)
    {
        if (!is_string($query)) {
            throw new InvalidArgumentException('Query string must be a string');
        }
        if (strpos($query, '#') !== false) {
            throw new InvalidArgumentException('Query string must not include a URI fragment');
        }
        $query = $this->filterQuery($query);
        if ($query === $this->query) {
            // Do nothing if no change was made.
            return clone $this;
        }
        $new = clone $this;
        $new->query = $query;
        return $new;
    }

Usage Example

Example #1
0
 public function testStripsQueryPrefixIfPresent()
 {
     $uri = new Uri('http://example.com');
     $new = $uri->withQuery('?foo=bar');
     $this->assertEquals('foo=bar', $new->getQuery());
 }
All Usage Examples Of Phly\Http\Uri::withQuery