The Port component

The Port class represents the URI Port component. Apart from the package common API, the class exposes an additional toInt method which returns the component value as an integer or null if the component is not defined.


use League\Uri\Components\Port;

$port = Port::new(443);
$port->value();                //returns '443'
$port->toInt();                //returns 443
echo $port;                    //displays '443'
echo $port->toString();        //displays '443'
echo $port->getUriComponent(); //displays ':443'

$nullPort = Port::new();
$nullPort->value();                //returns null
$nullPort->toInt();                //returns null
echo $nullPort;                    //displays ''
echo $nullPort->toString();        //displays ''
echo $nullPort->getUriComponent(); //displays ''

The object can not be modified, you are required to instantiate a new object.

The delimiter : is not part of the component value and must not be added.

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