madkom / uri
Uniform Resource Identifier (URI) and Uniform Resource Locator (URL)
Installs: 1 052
Dependents: 1
Suggesters: 0
Security: 0
Stars: 2
Watchers: 5
Forks: 1
Open Issues: 0
Requires
- php: ~7
- madkom/collection: 1.*
- madkom/regex: 1.*
- rize/uri-template: ^0.3.0
- true/punycode: ^2.0
Requires (Dev)
- clover/dump: dev-master
- henrikbjorn/phpspec-code-coverage: @dev
- instaclick/object-calisthenics-sniffs: @dev
- jakub-onderka/php-console-highlighter: 0.*
- jakub-onderka/php-parallel-lint: 0.*
- mdarse/phpunit-notifier: @dev
- phpspec/phpspec: @dev
- phpspec/prophecy: dev-master
- phpunit/phpcov: *
- phpunit/phpunit: 5.*
- satooshi/php-coveralls: 1.0.*@dev
- squizlabs/php_codesniffer: ^2.3
- symfony/var-dumper: ^3.0
This package is not auto-updated.
Last update: 2024-12-21 20:30:30 UTC
README
This library implements URI and URL specification and URI Templates, based on RFC3986 and RFC6570 (depends on external lib).
Features
This library can create objects like:
- Uri RFC3986 - includes wide abstraction with: Scheme, Authority, Path, Query, Fragment
- UriReference RFC3986 - can be resolved with valid Uri (eg.
$resolvedUri = $uriReference->resolve($uri);
) - UriTemplate RFC6570 - produces Uri or UriReference objects (depends on template)
Installation
Install with Composer
composer require madkom/uri
Requirements
This library requires PHP in ~7
version.
At this point this library depends on another own library madkom/collection and some external packages:
- rize/uri-template: for UriTemplate impl
- true/punycode: for IDNA domain names conversion
Usage
Parsing url string:
use Madkom\Uri\UriFactory; use Madkom\Uri\Uri; $factory = new UriFactory(); /** @var Uri $uri */ $uri = $factory->createUri('http://user:pass@host.tld/some/path?and=query¶m=2#fragment'); $uri->getScheme(); // Instance of \Madkom\Uri\Scheme\Http $uri->getAuthority(); // Instance of \Madkom\Uri\Authority $uri->getPath(); // Instance of \Madkom\Uri\Path $uri->getQuery(); // Instance of \Madkom\Uri\Query
TODO Missing fragment impl yet.
Parsing and resolving UriReference:
use Madkom\Uri\UriFactory; use Madkom\Uri\Uri; use Madkom\Uri\UriReference; $factory = new UriFactory(); /** @var Uri $uri */ $uri = $factory->createUri('http://user:pass@host.tld/some/path?and=query¶m=2#fragment'); /** @var UriReference $uriReference */ $uriReference = $factory->createUriReference('../another/path?and=different'); (string)$uriReference->resolveUri($uri); // http://user:pass@host.tld/some/another/path?and=different
Parsing isbn uri:
use Madkom\Uri\UriFactory; use Madkom\Uri\Uri; $factory = new UriFactory(); /** @var Uri $uri */ $uri = $factory->createUri('isbn:978-83-283-0525-0'); // Instance of \Madkom\Uri\Uri $uri->getScheme(); // Instance of \Madkom\Uri\Scheme\Custom $uri->getAuthority(); // NULL $uri->getPath(); // Instance of \Madkom\Uri\Path with "978-83-283-0525-0" $uri->getQuery(); // Instance of \Madkom\Uri\Query which is empty
Creating URI object:
use Madkom\Uri\Uri; use Madkom\Uri\Scheme\Https; use Madkom\Uri\Authority; use Madkom\Uri\Authority\Host\IPv6; use Madkom\Uri\Authority\UserInfo; use Madkom\Uri\Path; use Madkom\Uri\Query; use Madkom\Uri\Query\Parameter; /** @var Uri $uri */ $uri = new Uri( new Https(), new Authority( new IPv6('::1'), 443, new UserInfo('user', 'pass') ), new Path([ 'some', 'path' ]), new Query([ new Parameter('name', 'value') ]) ); $uri->toString(); // https://user:pass@[::1]:443/some/path?name=value (string)$uri; // same as above
TODO
- Implement Uri to string conversion
- Implement fragment component
- Replace IRI library with RFC Regex in
\Madkom\Uri\Parser
- Implement additional parsing modes in
\Madkom\Uri\Parser\Query
for various languages (parameter duplicate problem) - Implement normalization
- Implement UriReference based on RFC3986
License
The MIT License (MIT)
Copyright (c) 2016 Madkom S.A.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.