-
-
Notifications
You must be signed in to change notification settings - Fork 134
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
1 parent
731f6e1
commit fdbffb2
Showing
15 changed files
with
789 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace Symfony\Polyfill\Php85\Exception; | ||
|
||
class ParsingException extends \RuntimeException | ||
{ | ||
} |
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,19 @@ | ||
Copyright (c) 2024-present Fabien Potencier | ||
|
||
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. |
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,14 @@ | ||
Symfony Polyfill / Php85 | ||
======================== | ||
|
||
This component provides features added to PHP 8.5 core: | ||
|
||
- [RFC3986 and WHATWG compliant URI parsing support](https://wiki.php.net/rfc/url_parsing_api) | ||
|
||
More information can be found in the | ||
[main Polyfill README](https://github.com/symfony/polyfill/blob/main/README.md). | ||
|
||
License | ||
======= | ||
|
||
This library is released under the [MIT license](LICENSE). |
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,18 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Uri; | ||
|
||
if (\PHP_VERSION_ID < 80500) { | ||
class Rfc3986Uri extends \Symfony\Polyfill\Php85\Uri\Rfc3986Uri | ||
{ | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Uri; | ||
|
||
use Symfony\Polyfill\Php85 as p; | ||
|
||
if (\PHP_VERSION_ID < 80500) { | ||
abstract class Uri extends p\Uri\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,18 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Uri; | ||
|
||
if (\PHP_VERSION_ID < 80500) { | ||
final class WhatWgError extends \Symfony\Polyfill\Php85\Uri\WhatWgError | ||
{ | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Uri; | ||
|
||
if (\PHP_VERSION_ID < 80500) { | ||
class WhatWgUri extends \Symfony\Polyfill\Php85\Uri\WhatWgUri | ||
{ | ||
} | ||
} |
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,81 @@ | ||
<?php | ||
|
||
namespace Symfony\Polyfill\Php85\Uri; | ||
|
||
use Symfony\Polyfill\Php85\Exception\ParsingException; | ||
|
||
/** | ||
* @author Alexandre Daubois <alex.daubois@gmail.com> | ||
* | ||
* @internal | ||
*/ | ||
class Rfc3986Uri extends \Uri\Uri | ||
{ | ||
public function __construct(string $uri, ?string $baseUrl = null) | ||
{ | ||
if ('' === trim($uri)) { | ||
throw new \ValueError('Argument #1 ($uri) cannot be empty'); | ||
} | ||
|
||
if (null !== $baseUrl && '' === trim($baseUrl)) { | ||
throw new \ValueError('Argument #2 ($baseUrl) cannot be empty'); | ||
} | ||
|
||
try { | ||
$this->parse($uri, $baseUrl); | ||
} catch (ParsingException) { | ||
throw new \Error('Argument #1 ($uri) must be a valid URI'); | ||
} | ||
} | ||
|
||
private function parse(string $uri, ?string $baseUrl): void | ||
{ | ||
if (!preg_match('/^[a-zA-Z][a-zA-Z\d+\-.]*:/', $uri) && null !== $baseUrl) { | ||
// uri is a relative uri and bse url exists | ||
$this->parse(rtrim($baseUrl, '/').'/'.ltrim($uri, '/'), null); | ||
|
||
return; | ||
} | ||
|
||
if (preg_match('/[^\x20-\x7e]/', $uri)) { | ||
// the string contains non-ascii chars | ||
throw new ParsingException(); | ||
} | ||
|
||
preg_match(self::URI_GLOBAL_REGEX, $uri, $matches); | ||
if (!$matches || !isset($matches['scheme']) || '' === $matches['scheme']) { | ||
//throw new InvalidUriException($uri); | ||
} | ||
|
||
if (preg_match('~'.$matches['scheme'].':/(?!/)~', $uri)) { | ||
//throw new InvalidUriException($uri); | ||
} | ||
|
||
if (isset($matches['authority'])) { | ||
if (!str_contains($uri, '://') && '' !== $matches['authority']) { | ||
//throw new InvalidUriException($uri); | ||
} | ||
|
||
preg_match(self::URI_AUTHORITY_REGEX, $matches['authority'], $authMatches); | ||
|
||
$matches = array_merge($matches, $authMatches); | ||
unset($matches['authority']); | ||
} | ||
|
||
$matches = array_filter($matches, function (string $value) { return '' !== $value; }); | ||
|
||
if (isset($matches['host']) && false === \filter_var($matches['host'], FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)) { | ||
// the host contains invalid code points | ||
throw new ParsingException(); | ||
} | ||
|
||
$this->scheme = $matches['scheme'] ?? null; | ||
$this->user = isset($matches['user']) ? rawurldecode($matches['user']) : null; | ||
$this->password = isset($matches['pass']) ? rawurldecode($matches['pass']) : null; | ||
$this->host = $matches['host'] ?? null; | ||
$this->port = $matches['port'] ?? null; | ||
$this->path = isset($matches['path']) ? ltrim($matches['path'], '/') : null; | ||
$this->query = $matches['query'] ?? null; | ||
$this->fragment = $matches['fragment'] ?? null; | ||
} | ||
} |
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,133 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Polyfill\Php85\Uri; | ||
|
||
/** | ||
* @author Alexandre Daubois <alex.daubois@gmail.com> | ||
* | ||
* @internal | ||
*/ | ||
abstract class Uri implements \Stringable | ||
{ | ||
protected const URI_GLOBAL_REGEX = '/^(?:(?P<scheme>[^:\/?#]+):)?(?:\/\/(?P<authority>[^\/?#]*))?(?P<path>[^?#]*)(?:\?(?P<query>[^#]*))?(?:#(?P<fragment>.*))?$/'; | ||
protected const URI_AUTHORITY_REGEX = '/^(?:(?P<user>[^:@]*)(?::(?P<pass>[^@]*))?@)?(?P<host>[^:]*)(?::(?P<port>\d*))?$/'; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
protected $scheme; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
protected $user; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
protected $password; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
protected $host; | ||
|
||
/** | ||
* @var int|null | ||
*/ | ||
protected $port; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
protected $path; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
protected $query; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
protected $fragment; | ||
|
||
public static function fromRfc3986(string $uri, ?string $baseUrl = null): ?static | ||
{ | ||
try { | ||
return new Rfc3986Uri($uri, $baseUrl); | ||
} catch (\ValueError $error) { | ||
throw $error; | ||
} catch (\Error $error) { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* @param array<int, WhatWgError> $errors | ||
*/ | ||
public static function fromWhatWg(string $uri, ?string $baseUrl = null, &$errors = null): ?static | ||
{ | ||
$uri = new WhatWgUri($uri, $baseUrl, $errors); | ||
|
||
if ($errors) { | ||
return null; | ||
} | ||
|
||
return $uri; | ||
} | ||
|
||
public function getScheme(): ?string | ||
{ | ||
return $this->scheme; | ||
} | ||
|
||
public function getUser(): ?string | ||
{ | ||
return $this->user; | ||
} | ||
|
||
public function getPassword(): ?string | ||
{ | ||
return $this->password; | ||
} | ||
|
||
public function getHost(): ?string | ||
{ | ||
return $this->host; | ||
} | ||
|
||
public function getPort(): ?int | ||
{ | ||
return $this->port; | ||
} | ||
|
||
public function getPath(): ?string | ||
{ | ||
return $this->path; | ||
} | ||
|
||
public function getQuery(): ?string | ||
{ | ||
return $this->query; | ||
} | ||
|
||
public function getFragment(): ?string | ||
{ | ||
return $this->fragment; | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
|
||
} | ||
} |
Oops, something went wrong.