The League of Extraordinary Packages

Our Packages:

Presented by The League of Extraordinary Packages

Getting Started


Uri Schemes

Uri manipulation

Uri Parts API


Upgrading Guide

URI Handling

URI instantiation

To ease URI instantiation, and because URIs come in different forms we used named constructors to offer several ways to instantiate the object.

If a new instance can not be created an InvalidArgumentException exception is thrown

From a string


public static Uri::createFromString(string $uri = ''): Uri

Using the createFromString static method you can instantiate a new URI object from a string or from any object that implements the __toString method. Internally, the string will be parsed using the library internal URI parser.


use League\Uri\Schemes\Ftp as FtpUri;

$uri = FtpUri::createFromString(';type=i');

From parse_url results


public static Uri::createFromComponents(array $components = []): Uri

You can also instantiate a new URI object using the createFromComponents named constructor by giving it the result of PHP’s function parse_url or the library internal URI parser.


use League\Uri\Schemes\Ws as WsUri;

$components = parse_url('wss://');

$uri = WsUri::createFromComponents($components);
It is not recommend to instantiate an URI object using the default constructor. It is easier to always use the documentated named constructors since each URI object requires a specific set of URI components objects.

Generic URI Handling

Out of the box the library provides the following specialized classes:

But you can easily create your own class to manage others scheme specific URI.

URI normalization

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

These non destructives rules are:


use League\Uri\Schemes\Http as HttpUri;

$uri = HttpUri::createFromString("hTTp:// ld?who=f 3#title");
echo $uri; //displays