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.
- Loading branch information
Showing
6 changed files
with
350 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
/** | ||
* League.Uri (http://uri.thephpleague.com) | ||
* | ||
* @package League\Uri | ||
* @subpackage League\Uri | ||
* @author Ignace Nyamagana Butera <[email protected]> | ||
* @license https://github.com/thephpleague/uri-parser/blob/master/LICENSE (MIT License) | ||
* @version 1.1.0 | ||
* @link https://github.com/thephpleague/uri-parser/ | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace League\Uri; | ||
|
||
/** | ||
* Returns whether the URI host component is valid according to RFC3986. | ||
* | ||
* @see https://tools.ietf.org/html/rfc3986#section-3.2.2 | ||
* @see Parser::isHost() | ||
* | ||
* @param string $host | ||
* | ||
* @return bool | ||
*/ | ||
function is_host(string $host): bool | ||
{ | ||
static $parser; | ||
|
||
$parser = $parser ?? new Parser(); | ||
|
||
return $parser->isHost($host); | ||
} | ||
|
||
/** | ||
* Parse an URI string into its components. | ||
* | ||
* This method parses a URL and returns an associative array containing any | ||
* of the various components of the URL that are present. | ||
* | ||
* @see https://tools.ietf.org/html/rfc3986 | ||
* @see https://tools.ietf.org/html/rfc3986#section-2 | ||
* @see Parser::__invoke() | ||
* | ||
* @param string $uri | ||
* | ||
* @throws Exception if the URI contains invalid characters | ||
* | ||
* @return array | ||
*/ | ||
function parse(string $uri): array | ||
{ | ||
static $parser; | ||
|
||
$parser = $parser ?? new Parser(); | ||
|
||
return $parser($uri); | ||
} | ||
|
||
/** | ||
* Generate the URI string representation from its hash representation | ||
* returned by Parser::__invoke() or PHP's parse_url | ||
* | ||
* If you supply your own hash you are responsible for providing | ||
* valid components without their URI delimiters. | ||
* | ||
* For security reason the pass component has been deprecated | ||
* as per RFC3986 and is never returned in the URI string | ||
* | ||
* @see https://tools.ietf.org/html/rfc3986#section-5.3 | ||
* @see https://tools.ietf.org/html/rfc3986#section-7.5 | ||
* | ||
* @param array $components | ||
* | ||
* @return string | ||
*/ | ||
function build(array $components): string | ||
{ | ||
$uri = $components['path'] ?? ''; | ||
if (isset($components['query'])) { | ||
$uri .= '?'.$components['query']; | ||
} | ||
|
||
if (isset($components['fragment'])) { | ||
$uri .= '#'.$components['fragment']; | ||
} | ||
|
||
if (isset($components['host'])) { | ||
$authority = $components['host']; | ||
if (isset($components['port'])) { | ||
$authority .= ':'.$components['port']; | ||
} | ||
|
||
if (isset($components['user'])) { | ||
$authority = $components['user'].'@'.$authority; | ||
} | ||
|
||
$uri = '//'.$authority.$uri; | ||
} | ||
|
||
if (isset($components['scheme'])) { | ||
return $components['scheme'].':'.$uri; | ||
} | ||
|
||
return $uri; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
// Don't redefine the functions if included multiple times. | ||
if (!function_exists('League\Uri\parse')) { | ||
require __DIR__.'/functions.php'; | ||
} |
Oops, something went wrong.