You are here

public function Uri::withQuery in Zircon Profile 8

Same name in this branch
  1. 8 vendor/zendframework/zend-diactoros/src/Uri.php \Zend\Diactoros\Uri::withQuery()
  2. 8 vendor/guzzlehttp/psr7/src/Uri.php \GuzzleHttp\Psr7\Uri::withQuery()
Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-diactoros/src/Uri.php \Zend\Diactoros\Uri::withQuery()

Return an instance with the specified query string.

This method MUST retain the state of the current instance, and return an instance that contains the specified query string.

Users can provide both encoded and decoded query characters. Implementations ensure the correct encoding as outlined in getQuery().

An empty query string value is equivalent to removing the query string.

Parameters

string $query The query string to use with the new instance.:

Return value

self A new instance with the specified query string.

Throws

\InvalidArgumentException for invalid query strings.

Overrides UriInterface::withQuery

File

vendor/zendframework/zend-diactoros/src/Uri.php, line 375

Class

Uri
Implementation of Psr\Http\UriInterface.

Namespace

Zend\Diactoros

Code

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;
}