This repository has been archived by the owner on Nov 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- renamed test directory - improve internal code quality - using PHP7 strict type mode - preparing 1.0.0 release
- Loading branch information
Showing
11 changed files
with
294 additions
and
368 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,175 +24,17 @@ $ composer require league/uri-parser | |
Documentation | ||
--------- | ||
|
||
This is a drop-in replacement to PHP's `parse_url` function, with the following differences: | ||
|
||
- The parser is RFC3986 compliant | ||
|
||
```php | ||
<?php | ||
|
||
use League\Uri\Parser; | ||
|
||
$parser = new Parser(); | ||
var_export($parser('http://[email protected]/')); | ||
//returns the following array | ||
//array( | ||
// 'scheme' => 'http', | ||
// 'user' => null, | ||
// 'pass' => null, | ||
// 'host' => 'foo.com', | ||
// 'port' => null, | ||
// 'path' => '', | ||
// 'query' => '@bar.com/', | ||
// 'fragment' => null, | ||
//); | ||
|
||
var_export(parse_url('http://[email protected]/')); | ||
//returns the following array | ||
//array( | ||
// 'scheme' => 'http', | ||
// 'host' => 'bar.com', | ||
// 'user' => 'foo.com?', | ||
// 'path' => '/', | ||
//); | ||
``` | ||
|
||
- The `Parser::__invoke` method always returns all URI components. | ||
|
||
```php | ||
<?php | ||
|
||
use League\Uri\Parser; | ||
|
||
$parser = new Parser(); | ||
var_export($parser('http://www.example.com/')); | ||
//returns the following array | ||
//array( | ||
// 'scheme' => 'http', | ||
// 'user' => null, | ||
// 'pass' => null, | ||
// 'host' => 'www.example.com', | ||
// 'port' => null, | ||
// 'path' => '/', | ||
// 'query' => null, | ||
// 'fragment' => null, | ||
//); | ||
|
||
var_export(parse_url('http://www.example.com/')); | ||
//returns the following array | ||
//array( | ||
// 'scheme' => 'http', | ||
// 'host' => 'www.example.com', | ||
// 'path' => '/', | ||
//); | ||
``` | ||
|
||
- Accessing individual component is simple without needing extra parameters: | ||
|
||
```php | ||
<?php | ||
|
||
use League\Uri\Parser; | ||
|
||
$uri = 'http://www.example.com/'; | ||
$parser = new Parser(); | ||
$parser($uri)['query']; //returns null | ||
parse_url($uri, PHP_URL_QUERY); //returns null | ||
``` | ||
|
||
- Empty component and undefined component are treated differently | ||
|
||
A distinction is made between an unspecified component, which will be set to `null` and an empty component which will be equal to the empty string. | ||
|
||
```php | ||
<?php | ||
|
||
use League\Uri\Parser; | ||
|
||
$uri = 'http://www.example.com/?'; | ||
$parser = new Parser(); | ||
$parser($uri)['query']; //returns '' | ||
parse_url($uri, PHP_URL_QUERY); //returns null | ||
``` | ||
|
||
- The path component is never equal to `null` | ||
|
||
Since a URI is made of at least a path component, this component is never equal to `null` | ||
|
||
```php | ||
<?php | ||
|
||
use League\Uri\Parser; | ||
|
||
$uri = 'http://www.example.com?'; | ||
$parser = new Parser(); | ||
$parser($uri)['path']; //returns '' | ||
parse_url($uri, PHP_URL_PATH); //returns null | ||
``` | ||
|
||
- On malformed URI, the parser will throw a `ParserException` exception which extends SPL `InvalidArgumentException` instead of returning `false`. | ||
|
||
```php | ||
<?php | ||
|
||
use League\Uri\Parser; | ||
|
||
$uri = '//user@:80'; | ||
$parser = new Parser(); | ||
$parser($uri); | ||
//throw a ParserException | ||
|
||
parse_url($uri); //returns false | ||
``` | ||
|
||
- Just like `parse_url`, the `League\Uri\Parser` only parses and extracts from the URI string its components. **You still need to validate them against its scheme specific rules.** | ||
|
||
```php | ||
<?php | ||
|
||
use League\Uri\Parser; | ||
|
||
$uri = 'http:www.example.com'; | ||
$parser = new Parser(); | ||
var_export($parser($uri)); | ||
//returns the following array | ||
//array( | ||
// 'scheme' => 'http', | ||
// 'user' => null, | ||
// 'pass' => null, | ||
// 'host' => null, | ||
// 'port' => null, | ||
// 'path' => 'www.example.com', | ||
// 'query' => null, | ||
// 'fragment' => null, | ||
//); | ||
``` | ||
|
||
**This invalid HTTP URI is successfully parsed.** | ||
Full documentation can be found at [uri.thephpleague.com](http://uri.thephpleague.com). | ||
|
||
Testing | ||
------- | ||
|
||
`URI Parser` has: | ||
|
||
- a [PHPUnit](https://phpunit.de) test suite. | ||
- a coding style compliance test suite using [PHP CS Fixer](http://cs.sensiolabs.org/). | ||
|
||
To run the tests, run the following command from the project folder. | ||
`League Uri Parser` has a [PHPUnit](https://phpunit.de) test suite and a coding style compliance test suite using [PHP CS Fixer](http://cs.sensiolabs.org/). To run the tests, run the following command from the project folder. | ||
|
||
```bash | ||
$ composer test | ||
``` | ||
|
||
Benchmark | ||
------- | ||
|
||
Additionally, a benchmark test suite using [PHP Bench](https://github.com/phpbench/phpbench) is provided. | ||
|
||
```bash | ||
$ composer benchmarks | ||
``` | ||
|
||
Contributing | ||
------- | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,11 @@ | |
* @author Ignace Nyamagana Butera <[email protected]> | ||
* @copyright 2016 Ignace Nyamagana Butera | ||
* @license https://github.com/thephpleague/uri-parser/blob/master/LICENSE (MIT License) | ||
* @version 0.2.0 | ||
* @version 1.0.0 | ||
* @link https://github.com/thephpleague/uri-parser/ | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace League\Uri; | ||
|
||
use InvalidArgumentException; | ||
|
@@ -31,7 +33,7 @@ class Exception extends InvalidArgumentException | |
* | ||
* @return static | ||
*/ | ||
public static function createFromInvalidCharacters($uri) | ||
public static function createFromInvalidCharacters(string $uri) | ||
{ | ||
return new static(sprintf('The submitted uri `%s` contains invalid characters', $uri)); | ||
} | ||
|
@@ -43,7 +45,7 @@ public static function createFromInvalidCharacters($uri) | |
* | ||
* @return static | ||
*/ | ||
public static function createFromInvalidScheme($uri) | ||
public static function createFromInvalidScheme(string $uri) | ||
{ | ||
return new static(sprintf('The submitted uri `%s` contains an invalid scheme', $uri)); | ||
} | ||
|
@@ -55,15 +57,27 @@ public static function createFromInvalidScheme($uri) | |
* | ||
* @return static | ||
*/ | ||
public static function createFromInvalidHost($host) | ||
public static function createFromInvalidHost(string $host) | ||
{ | ||
return new static(sprintf('The submitted host `%s` is invalid', $host)); | ||
} | ||
|
||
/** | ||
* Returns a new Instance from an error in port validation | ||
* | ||
* @param string $port | ||
* @param string $hostname | ||
* | ||
* @return static | ||
*/ | ||
public static function createFromInvalidHostname(string $hostname) | ||
{ | ||
return new static(sprintf('The submitted hostname `%s` is invalid', $hostname)); | ||
} | ||
|
||
/** | ||
* Returns a new Instance from an error in port validation | ||
* | ||
* @param mixed $port | ||
* | ||
* @return static | ||
*/ | ||
|
@@ -79,7 +93,7 @@ public static function createFromInvalidPort($port) | |
* | ||
* @return static | ||
*/ | ||
public static function createFromInvalidPath($uri) | ||
public static function createFromInvalidPath(string $uri) | ||
{ | ||
return new static(sprintf('The submitted uri `%s` contains an invalid path', $uri)); | ||
} | ||
|
Oops, something went wrong.