You are here

public function Uri::withHost in Zircon Profile 8

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

Return an instance with the specified host.

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

An empty host value is equivalent to removing the host.

Parameters

string $host The hostname to use with the new instance.:

Return value

self A new instance with the specified host.

Throws

\InvalidArgumentException for invalid hostnames.

Overrides UriInterface::withHost

File

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

Class

Uri
Implementation of Psr\Http\UriInterface.

Namespace

Zend\Diactoros

Code

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

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