league / uri
URI manipulation library
Fund package maintenance!
nyamsprod
Installs: 30 376 877
Dependents: 208
Suggesters: 7
Security: 0
Stars: 897
Watchers: 15
Forks: 64
Open Issues: 0
Requires
- php: ^8.1
- ext-json: *
- league/uri-interfaces: ^2.3
- psr/http-message: ^1.0.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^v3.9.5
- nyholm/psr7: ^1.5.1
- php-http/psr7-integration-tests: ^1.1.1
- phpbench/phpbench: ^1.2.6
- phpstan/phpstan: ^1.8.5
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.1.1
- phpstan/phpstan-strict-rules: ^1.4.3
- phpunit/phpunit: ^9.5.24
- psr/http-factory: ^1.0.1
Suggests
- ext-fileinfo: Needed to create Data URI from a filepath
- ext-intl: Needed to improve host validation
- league/uri-components: Needed to easily manipulate URI objects
- psr/http-factory: Needed to use the URI factory
Conflicts
- league/uri-schemes: ^1.0
README
The Uri
package provides simple and intuitive classes to manage URIs in PHP. You will be able to
- parse, build and resolve URIs
- create URIs from different sources (string, PHP environment, base URI, URI template, ...);
- handle internalisation;
- infer properties and features from URIs;
<?php use League\Uri\UriTemplate; $template = 'https://api.twitter.com:443/{version}/search/{term:1}/{term}/{?q*,limit}#title'; $defaultVariables = ['version' => '1.1']; $params = [ 'term' => 'john', 'q' => ['a', 'b'], 'limit' => '10', ]; $uriTemplate = new UriTemplate($template, $defaultVariables); $uri = $uriTemplate->expand($params); // $uri is a League\Uri\Uri object echo $uri->getScheme(); //displays "https" echo $uri->getAuthority(); //displays "api.twitter.com:443" echo $uri->getPath(); //displays "/1.1/search/j/john/" echo $uri->getQuery(); //displays "q=a&q=b&limit=10" echo $uri->getFragment(); //displays "title" echo $uri; //displays "https://api.twitter.com:443/1.1/search/j/john/?q=a&q=b&limit=10#title" echo json_encode($uri); //displays "https:\/\/api.twitter.com:443\/1.1\/search\/j\/john\/?q=a&q=b&limit=10#title"
Highlights
- Simple API
- RFC3986, RFC3987 and RFC6570 compliant
- Implements the
UriInterface
from PSR-7 - Fully documented
- Framework Agnostic
System Requirements
- You require PHP >= 7.3 but the latest stable version of PHP is recommended
- You will need the ext-intl to handle i18n URI.
- Since version 6.2.0 you will need the ext-fileinfo to handle Data URI creation from a filepath.
Dependencies
In order to handle IDN host you are required to also install the intl
extension otherwise an exception will be thrown when attempting to validate such host.
In order to create Data URI from a filepath, since version 6.2
, you are required to also install the fileinfo
extension otherwise an exception will be thrown.
Installation
$ composer require league/uri
Documentation
Full documentation can be found at uri.thephpleague.com.
Contributing
⚠️ this is a sub-split, for development, pull requests and issues, visit: https://github.com/thephpleague/uri-src
License
The MIT License (MIT). Please see License File for more information.