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

The Authority part

The League\Uri\Components\Authority class ease URI authority part creation and manipulation. This object exposes:

but also provide specific methods to work with a URI authority part.

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

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


Using the default constructor

The default constructor is deprecated starting with version 2.3.0. It should be replaced by one of the several new named constructors.

public Authority::__construct($authority = null): void

submitted string is normalized to be RFC3986 compliant.

Using a string


use League\Uri\Components\Authority;

$authority = Authority::createFromString('');
$authority->getContent(); //returns ''

if no string is given a instance is returns using the empty string.

Using Uri components


use League\Uri\Components\Authority;
use League\Uri\UriString;

$authority = Authority::createFromComponents(
$authority->getContent(); //returns ''

If you supply your own hash to createFromComponents, you are responsible for providing well parsed components without their URI delimiters.

Using an URI object

The URI must implements League UriInterface or PSR-7 UriInterface.


use Laminas\Diactoros\Uri as LaminasUri;
use League\Uri\Components\Authority;

$psr7Uri = new LaminasUri("");

$authority = Authority::createFromUri($psr7Uri);
$authority->getPort(); //return null;

Using null


use League\Uri\Components\Authority;

$authority = Authority::createFromNull();
$authority->getContent(); //return null;

Authority validation

A League\Uri\Contracts\UriException exception is triggered if an invalid Authority value is given.

$uri = Authority::createFromString(':80');
// throws a League\Uri\Exceptions\SyntaxError
// because the URI string is invalid

Accessing properties

The Authority object exposes the following specific methods.

public function Authority::getUserInfo(void): ?string
public function Authority::getHost(void): ?string
public function Authority::getPort(void): ?int

You can access the authority string, its individual parts and components using their respective getter methods. This lead to the following result for a simple HTTP URI:

$uri = Authority::createFromString("");
echo $uri->getUserInfo();  //displays "foo:bar"
echo $uri->getHost();      //displays ""
echo $uri->getPort();      //displays 81 as an integer
echo $uri;
//displays ""
echo json_encode($uri);
//displays ""

Modifying properties

To replace one of the URI component you can use the modifying methods exposed by all URI object. If the modifications do not alter the current object, it is returned as is, otherwise, a new modified object is returned.

Any modification method can trigger a League\Uri\Contracts\UriException exception if the resulting URI is not valid. Just like with the instantiation methods, validition is scheme dependant.


public function Authority::withUserInfo(?string $user, ?string $password = null): self
public function Authority::withHost(?string $host): self
public function Authority::withPort(?int $port): self

Since All URI object are immutable you can chain each modifying methods to simplify URI creation and/or modification.

$uri = Authority::createFromString("")
    ->withUserInfo("foo", "bar")

echo $uri->getUriComponent(); //displays "//"


Out of the box the package normalizes the URI part according to the non destructive rules of RFC3986.

These non-destructive rules are:

$uri = new Uri("");
echo $uri; //displays

Host conversion depends on the presence of the ext-intl extension. Otherwise the code will trigger a IdnSupportMissing exception