You are here

public function Uri::withFragment in Zircon Profile 8

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

Return an instance with the specified URI fragment.

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

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

An empty fragment value is equivalent to removing the fragment.

Parameters

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

Return value

self A new instance with the specified fragment.

Overrides UriInterface::withFragment

File

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

Class

Uri
Implementation of Psr\Http\UriInterface.

Namespace

Zend\Diactoros

Code

public function withFragment($fragment) {
  if (!is_string($fragment)) {
    throw new InvalidArgumentException(sprintf('%s expects a string argument; received %s', __METHOD__, is_object($fragment) ? get_class($fragment) : gettype($fragment)));
  }
  $fragment = $this
    ->filterFragment($fragment);
  if ($fragment === $this->fragment) {

    // Do nothing if no change was made.
    return clone $this;
  }
  $new = clone $this;
  $new->fragment = $fragment;
  return $new;
}