--- layout: default title: The User information component redirect_from: - /5.0/components/userinfo/ --- The UserInfo ======= The library provides a `UserInfo` class to ease user information creation and manipulation. This URI component object exposes the [package common API](/components/1.0/api/), but also provide specific methods to work with the URI user information part. ## Creating a new object ~~~php submitted string is normalized to be RFC3986 compliant.

If the submitted value is not valid a League\Uri\Components\Exception exception is thrown.

The `League\Uri\Components\Exception` extends PHP's SPL `InvalidArgumentException`. ## Accessing User information content ~~~php getUser(); //return 'foo' $info->getPass(); //return 'bar' ~~~ Just like the `ComponentInterface::getContent` method both `UserInfo::getUser` and `UserInfo::getPass` accept an optional `$enc_type` argument to specify how to encode the specify how to encode the returned value. ~~~php getUser(UserInfo::RFC3987_ENCODING); //return 'bébé' $info->getUser(UserInfo::RFC3986_ENCODING); //return 'b%C3%A9b%C3%A9' $info->getUser(); //return 'b%C3%A9b%C3%A9' ~~~ ## Modifying the user information ~~~php 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. ~~~php withUserInfo('john', 'doe'); echo $new_info; //displays john:doe echo $info; //displays foo:bar ~~~

If the modification is invalid a League\Uri\Components\Exception exception is thrown.