You are here

public function Uri::withPath in Zircon Profile 8

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

Return an instance with the specified path.

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

The path can either be empty or absolute (starting with a slash) or rootless (not starting with a slash). Implementations MUST support all three syntaxes.

If the path is intended to be domain-relative rather than path relative then it must begin with a slash ("/"). Paths not starting with a slash ("/") are assumed to be relative to some base path known to the application or consumer.

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

Parameters

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

Return value

self A new instance with the specified path.

Throws

\InvalidArgumentException for invalid paths.

Overrides UriInterface::withPath

File

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

Class

Uri
Implementation of Psr\Http\UriInterface.

Namespace

Zend\Diactoros

Code

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