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.
- Adding the ParserException Exception class to isolate Parser Exception the ParserException extends InvalidArgumentException so there are two ways to catch the thrown error - Improve URI parsing by removing all regular expressions.
- Loading branch information
Showing
7 changed files
with
562 additions
and
155 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,27 +35,27 @@ This is a drop-in replacement to PHP's `parse_url` function, with the following | |
use League\Uri\Parser; | ||
|
||
$parser = new Parser(); | ||
var_dump($parser('http://[email protected]/')); | ||
var_export($parser('http://[email protected]/')); | ||
//returns the following array | ||
//[ | ||
// 'scheme' => 'http', | ||
// 'user' => null, | ||
// 'pass' => null, | ||
// 'host' => 'foo.com', | ||
// 'port' => null, | ||
// 'path' => '', | ||
// 'query' => '@bar.com/', | ||
// 'fragment' => null, | ||
//]; | ||
|
||
var_dump(parse_url('http://[email protected]/')); | ||
//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 | ||
//[ | ||
// 'scheme' => 'http', | ||
// 'host' => 'bar.com', | ||
// 'user' => 'foo.com?', | ||
// 'path' => '/', | ||
//]; | ||
//array( | ||
// 'scheme' => 'http', | ||
// 'host' => 'bar.com', | ||
// 'user' => 'foo.com?', | ||
// 'path' => '/', | ||
//); | ||
``` | ||
|
||
- The `Parser::__invoke` method always returns all URI components. | ||
|
@@ -66,26 +66,26 @@ var_dump(parse_url('http://[email protected]/')); | |
use League\Uri\Parser; | ||
|
||
$parser = new Parser(); | ||
var_dump($parser('http://www.example.com/')); | ||
var_export($parser('http://www.example.com/')); | ||
//returns the following array | ||
//[ | ||
// 'scheme' => 'http', | ||
// 'user' => null, | ||
// 'pass' => null, | ||
// 'host' => 'www.example.com', | ||
// 'port' => null, | ||
// 'path' => '/', | ||
// 'query' => null, | ||
// 'fragment' => null, | ||
//]; | ||
|
||
var_dump(parse_url('http://www.example.com/')); | ||
//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 | ||
//[ | ||
// 'scheme' => 'http', | ||
// 'host' => 'www.example.com', | ||
// 'path' => '/', | ||
//]; | ||
//array( | ||
// 'scheme' => 'http', | ||
// 'host' => 'www.example.com', | ||
// 'path' => '/', | ||
//); | ||
``` | ||
|
||
- Accessing individual component is simple without needing extra parameters: | ||
|
@@ -140,18 +140,18 @@ use League\Uri\Parser; | |
|
||
$uri = 'http:www.example.com'; | ||
$parser = new Parser(); | ||
var_dump($parser($uri)); | ||
var_export($parser($uri)); | ||
//returns the following array | ||
//[ | ||
// 'scheme' => 'http', | ||
// 'user' => null, | ||
// 'pass' => null, | ||
// 'host' => null, | ||
// 'port' => null, | ||
// 'path' => 'www.example.com', | ||
// 'query' => null, | ||
// 'fragment' => null, | ||
//]; | ||
//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.** | ||
|
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
class ParserBench | ||
{ | ||
private $uri = 'ftp://cnn.example.com&[email protected]/top_story.htm'; | ||
private $uri = 'https://cnn.example.com&[email protected]/top_story.htm'; | ||
|
||
/** | ||
* Baseline - comparison with parse_url | ||
|
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
Oops, something went wrong.