Simple URI wrapper for PHP 7.1+ based on RFC-3986, PSR-7 & PSR-17

v1.1.0 2020-04-12 18:46 UTC

README

Gitter Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version Total Downloads License

Awards

SymfonyInsight

Installation

composer require sunrise/uri

How to use?

use Sunrise\Uri\Uri;
use Sunrise\Uri\UriFactory;

// creates a new URI
$uri = new Uri('http://user:pass@localhost:3000/path?query#fragment');

// creates a new URI with a factory (is equivalent to `new Uri(...)`)
$uri = (new UriFactory)->createUri('http://user:pass@localhost:3000/path?query#fragment');

// list of withers
$uri->withScheme();
$uri->withUserInfo();
$uri->withHost();
$uri->withPort();
$uri->withPath();
$uri->withQuery();
$uri->withFragment();

// list of getters
$uri->getScheme();
$uri->getUserInfo();
$uri->getHost();
$uri->getPort();
$uri->getPath();
$uri->getQuery();
$uri->getFragment();
$uri->getAuthority();

// converts the URI to string
(string) $uri;

Another schemes

$uri = new Uri('mailto:test@example.com');

$uri->getScheme(); // mailto
$uri->getPath(); // test@example.com
$uri = new Uri('maps:?q=112+E+Chapman+Ave+Orange,+CA+92866');

$uri->getScheme(); // maps
$uri->getQuery(); // q=112+E+Chapman+Ave+Orange,+CA+92866
$uri = new Uri('tel:+1-816-555-1212');

$uri->getScheme(); // tel
$uri->getPath(); // +1-816-555-1212
$uri = new Uri('urn:oasis:names:specification:docbook:dtd:xml:4.1.2');

$uri->getScheme(); // urn
$uri->getPath(); // oasis:names:specification:docbook:dtd:xml:4.1.2

Test run

php vendor/bin/phpunit

Api documentation

https://phpdoc.fenric.ru/

Useful links