You are here

public function Uri::withScheme in Zircon Profile 8

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

Return an instance with the specified scheme.

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

Implementations MUST support the schemes "http" and "https" case insensitively, and MAY accommodate other schemes if required.

An empty scheme is equivalent to removing the scheme.

Parameters

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

Return value

self A new instance with the specified scheme.

Throws

\InvalidArgumentException for invalid or unsupported schemes.

Overrides UriInterface::withScheme

File

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

Class

Uri
Implementation of Psr\Http\UriInterface.

Namespace

Zend\Diactoros

Code

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

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