URI, URL and URN value objects

v1.0.5 2018-12-15 22:44 UTC

This package is auto-updated.

Last update: 2021-10-06 20:10:43 UTC



Library which contains value objects to represent URI, URL and URNs. The value objects are immutable so in case you change a value through a with* method you get a new instance of that object. There is also a uri resolver class to resolve a uri against a base uri.



$uri = new Uri('/bar?foo=bar');

$uri->getPath(); // /bar
$uri->getQuery(); // foo=bar
$uri->getParameters(); // ['foo' => 'bar']

$uri = $uri->withScheme('https');
$uri = $uri->withScheme('');

echo $uri->toString(); //

// the url object validates whether a scheme and host is available thus it is
// a valid url
$url = new Url($uri->toString());

// a urn provides additional getter to get the urn specific components. A urn
// must start with urn:
$urn = new Urn('urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66');

$urn->getNid(); // uuid
$urn->getNss(); // 6e8bc430-9c3a-11d9-9669-0800200c9a66