public function withPath($path)
{
if (!is_string($path)) {
throw new InvalidArgumentException('Invalid path provided; must be a string');
}
if (strpos($path, '?') !== false) {
throw new InvalidArgumentException('Invalid path provided; must not contain a query string');
}
if (strpos($path, '#') !== false) {
throw new InvalidArgumentException('Invalid path provided; must not contain a URI fragment');
}
$path = $this->filterPath($path);
if ($path === $this->path) {
// Do nothing if no change was made.
return clone $this;
}
$new = clone $this;
$new->path = $path;
return $new;
}