Please consider using the the latest stable version for any production code.

The UserInfo

The League\Uri\Components\UserInfo class eases user information creation and manipulation. This URI component object exposes the package common API, but also provide specific methods to work with the URI user information part.

Creating a new object

public UserInfo::__construct($user, $pass = null): void

submitted string is normalized to be RFC3986 compliant.

If the submitted value is not valid a League\Uri\Exceptions\SyntaxError exception is thrown.

Accessing User information content

public UserInfo::getUser(): ?string
public UserInfo::getPass(): ?string

To access the user login and password information you need to call the respective UserInfo::getUser and UserInfo::getPass methods like shown below.

$info = new UserInfo('foo', 'bar');
$info->getUser(); //return 'foo'
$info->getPass(); //return 'bar'

Modifying the user information

public UserInfo::withUserInfo($user, $password = null): self

If the modifications do not change the current object, it is returned as is, otherwise, a new modified object is returned.

Because the UserInfo is composed of at most two components the UserInfo::withUserInfo method is introduced to ease modify the object content.

$info = new UserInfo('foo', 'bar');
$new_info = $info->withUserInfo('john', 'doe');
echo $new_info; //displays john:doe
echo $info;     //displays foo:bar

If the submitted value is not valid a League\Uri\Exceptions\SyntaxError exception is thrown.