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