The User component
The library provides a User
class to ease user creation and manipulation.
Instantiation
Using the default constructor.
<?php
public function __contruct($user = null)
The constructor accepts:
- a valid string according to RFC3986 rules;
- the
null
value;
Example
<?php
use League\Uri\Components\User;
$user = new User('john');
echo $user->getContent(); //display 'john'
echo $user; //display 'john'
echo $user->getUriComponent(); //display 'john'
$user = new User();
echo $user->getContent(); //display null
echo $user; //display ''
echo $user->getUriComponent(); //display ''
Using a League Uri object
You can access a User
object with an already instantiated Uri
object.
<?php
use League\Uri\Schemes\Http as HttpUri;
$uri = HttpUri::createFromString('http://uri.thephpleague.com:82');
$user = $uri->user; // $user is a League\Uri\Components\User object;
Properties and Methods
The component representation, comparison and manipulation is done using the package UriPart and the Component interfaces methods.
User::getDecoded
<?php
public function User::getDecoded(void): null|string
Returns the decoded version of the getContent
method
Example
<?php
use League\Uri\Components\User;
$user = new User('frag:ment');
$user->getContent(); // display 'frag%3Ament'
$user->getDecoded(); // display 'frag:ment'