Intuitive
use League\Uri\Components\Query;
use League\Uri\Modifier;
use League\Uri\Uri;
$uri = Uri::new('http://example.com?q=value#fragment');
$uri->getScheme(); // returns 'http'
$uri->getHost(); // returns 'example.com'
$newUri = Modifier::from($uri)->appendQuery('q=new.Value');
echo $newUri; // 'http://example.com?q=value&q=new.Value#fragment'
$query = Query::fromUri($newUri);
$query->get('q'); // returns 'value'
$query->getAll('q'); // returns ['value', 'new.Value']
$query->parameter('q'); // returns 'new.Value'
The libraries manipulate URIs and their components using a simple yet expressive code.
Highlights
This suite of packages provides intuitive classes to parse, validate, format and manipulate URIs and their components. It is built to enable working with any kind of RFC3986 compliant URI and also follow closely the latest WHATWG Living standard specification.
It provides an enhanced replacement for PHP's parse_url
, http_build_query
, and PECL's http_build_url
functions.
Simple and extensible API
RFC3986 compliant
follows URL Living Standard specifications
Implements PSR-7
UriInterface
interfaceFramework-agnostic
Packages
building blocks
- uri-interfaces
- Represents the backbone of all the packages. It contains contracts and tools that can be used independently of any URI package.
- uri
- The main package. Its goal is to ease the generation and manipulation of URI objects, independently of their scheme.
- uri-components
- Complements the URI package, providing an object-oriented way to access and manipulate each component value of the underlying URI.
Questions?
The packages were created by Ignace Nyamagana Butera.
Find him
on Mastodon at @nyamsprod@phpc.social or
on Twitter at @nyamsprod