You are here

public function Uri::withUserInfo in Zircon Profile 8

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

Return an instance with the specified user information.

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

Password is optional, but the user information MUST include the user; an empty string for the user is equivalent to removing user information.

Parameters

string $user The user name to use for authority.:

null|string $password The password associated with $user.:

Return value

self A new instance with the specified user information.

Overrides UriInterface::withUserInfo

File

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

Class

Uri
Implementation of Psr\Http\UriInterface.

Namespace

Zend\Diactoros

Code

public function withUserInfo($user, $password = null) {
  if (!is_string($user)) {
    throw new InvalidArgumentException(sprintf('%s expects a string user argument; received %s', __METHOD__, is_object($user) ? get_class($user) : gettype($user)));
  }
  if (null !== $password && !is_string($password)) {
    throw new InvalidArgumentException(sprintf('%s expects a string password argument; received %s', __METHOD__, is_object($password) ? get_class($password) : gettype($password)));
  }
  $info = $user;
  if ($password) {
    $info .= ':' . $password;
  }
  if ($info === $this->userInfo) {

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