diff options
Diffstat (limited to 'guzzlehttp/psr7/src/UriNormalizer.php')
-rw-r--r-- | guzzlehttp/psr7/src/UriNormalizer.php | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/guzzlehttp/psr7/src/UriNormalizer.php b/guzzlehttp/psr7/src/UriNormalizer.php index 81419ead..e12971ed 100644 --- a/guzzlehttp/psr7/src/UriNormalizer.php +++ b/guzzlehttp/psr7/src/UriNormalizer.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace GuzzleHttp\Psr7; use Psr\Http\Message\UriInterface; @@ -15,18 +17,21 @@ final class UriNormalizer { /** * Default normalizations which only include the ones that preserve semantics. - * - * self::CAPITALIZE_PERCENT_ENCODING | self::DECODE_UNRESERVED_CHARACTERS | self::CONVERT_EMPTY_PATH | - * self::REMOVE_DEFAULT_HOST | self::REMOVE_DEFAULT_PORT | self::REMOVE_DOT_SEGMENTS */ - const PRESERVING_NORMALIZATIONS = 63; + public const PRESERVING_NORMALIZATIONS = + self::CAPITALIZE_PERCENT_ENCODING | + self::DECODE_UNRESERVED_CHARACTERS | + self::CONVERT_EMPTY_PATH | + self::REMOVE_DEFAULT_HOST | + self::REMOVE_DEFAULT_PORT | + self::REMOVE_DOT_SEGMENTS; /** * All letters within a percent-encoding triplet (e.g., "%3A") are case-insensitive, and should be capitalized. * * Example: http://example.org/a%c2%b1b → http://example.org/a%C2%B1b */ - const CAPITALIZE_PERCENT_ENCODING = 1; + public const CAPITALIZE_PERCENT_ENCODING = 1; /** * Decodes percent-encoded octets of unreserved characters. @@ -37,14 +42,14 @@ final class UriNormalizer * * Example: http://example.org/%7Eusern%61me/ → http://example.org/~username/ */ - const DECODE_UNRESERVED_CHARACTERS = 2; + public const DECODE_UNRESERVED_CHARACTERS = 2; /** * Converts the empty path to "/" for http and https URIs. * * Example: http://example.org → http://example.org/ */ - const CONVERT_EMPTY_PATH = 4; + public const CONVERT_EMPTY_PATH = 4; /** * Removes the default host of the given URI scheme from the URI. @@ -57,14 +62,14 @@ final class UriNormalizer * * Example: file://localhost/myfile → file:///myfile */ - const REMOVE_DEFAULT_HOST = 8; + public const REMOVE_DEFAULT_HOST = 8; /** * Removes the default port of the given URI scheme from the URI. * * Example: http://example.org:80/ → http://example.org/ */ - const REMOVE_DEFAULT_PORT = 16; + public const REMOVE_DEFAULT_PORT = 16; /** * Removes unnecessary dot-segments. @@ -74,7 +79,7 @@ final class UriNormalizer * * Example: http://example.org/../a/b/../c/./d.html → http://example.org/a/c/d.html */ - const REMOVE_DOT_SEGMENTS = 32; + public const REMOVE_DOT_SEGMENTS = 32; /** * Paths which include two or more adjacent slashes are converted to one. @@ -85,7 +90,7 @@ final class UriNormalizer * * Example: http://example.org//foo///bar.html → http://example.org/foo/bar.html */ - const REMOVE_DUPLICATE_SLASHES = 64; + public const REMOVE_DUPLICATE_SLASHES = 64; /** * Sort query parameters with their values in alphabetical order. @@ -98,7 +103,7 @@ final class UriNormalizer * Note: The sorting is neither locale nor Unicode aware (the URI query does not get decoded at all) as the * purpose is to be able to compare URIs in a reproducible way, not to have the params sorted perfectly. */ - const SORT_QUERY_PARAMETERS = 128; + public const SORT_QUERY_PARAMETERS = 128; /** * Returns a normalized URI. @@ -114,11 +119,9 @@ final class UriNormalizer * @param UriInterface $uri The URI to normalize * @param int $flags A bitmask of normalizations to apply, see constants * - * @return UriInterface The normalized URI - * * @link https://tools.ietf.org/html/rfc3986#section-6.2 */ - public static function normalize(UriInterface $uri, $flags = self::PRESERVING_NORMALIZATIONS) + public static function normalize(UriInterface $uri, int $flags = self::PRESERVING_NORMALIZATIONS): UriInterface { if ($flags & self::CAPITALIZE_PERCENT_ENCODING) { $uri = self::capitalizePercentEncoding($uri); @@ -171,16 +174,14 @@ final class UriNormalizer * @param UriInterface $uri2 An URI to compare * @param int $normalizations A bitmask of normalizations to apply, see constants * - * @return bool - * * @link https://tools.ietf.org/html/rfc3986#section-6.1 */ - public static function isEquivalent(UriInterface $uri1, UriInterface $uri2, $normalizations = self::PRESERVING_NORMALIZATIONS) + public static function isEquivalent(UriInterface $uri1, UriInterface $uri2, int $normalizations = self::PRESERVING_NORMALIZATIONS): bool { return (string) self::normalize($uri1, $normalizations) === (string) self::normalize($uri2, $normalizations); } - private static function capitalizePercentEncoding(UriInterface $uri) + private static function capitalizePercentEncoding(UriInterface $uri): UriInterface { $regex = '/(?:%[A-Fa-f0-9]{2})++/'; @@ -196,7 +197,7 @@ final class UriNormalizer ); } - private static function decodeUnreservedCharacters(UriInterface $uri) + private static function decodeUnreservedCharacters(UriInterface $uri): UriInterface { $regex = '/%(?:2D|2E|5F|7E|3[0-9]|[46][1-9A-F]|[57][0-9A])/i'; |