Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wordpres.../vendor_p.../guzzleht.../psr7/src
File: UriNormalizer.php
<?php
[0] Fix | Delete
[1] Fix | Delete
declare (strict_types=1);
[2] Fix | Delete
namespace YoastSEO_Vendor\GuzzleHttp\Psr7;
[3] Fix | Delete
[4] Fix | Delete
use YoastSEO_Vendor\Psr\Http\Message\UriInterface;
[5] Fix | Delete
/**
[6] Fix | Delete
* Provides methods to normalize and compare URIs.
[7] Fix | Delete
*
[8] Fix | Delete
* @author Tobias Schultze
[9] Fix | Delete
*
[10] Fix | Delete
* @see https://datatracker.ietf.org/doc/html/rfc3986#section-6
[11] Fix | Delete
*/
[12] Fix | Delete
final class UriNormalizer
[13] Fix | Delete
{
[14] Fix | Delete
/**
[15] Fix | Delete
* Default normalizations which only include the ones that preserve semantics.
[16] Fix | Delete
*/
[17] Fix | Delete
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;
[18] Fix | Delete
/**
[19] Fix | Delete
* All letters within a percent-encoding triplet (e.g., "%3A") are case-insensitive, and should be capitalized.
[20] Fix | Delete
*
[21] Fix | Delete
* Example: http://example.org/a%c2%b1b → http://example.org/a%C2%B1b
[22] Fix | Delete
*/
[23] Fix | Delete
public const CAPITALIZE_PERCENT_ENCODING = 1;
[24] Fix | Delete
/**
[25] Fix | Delete
* Decodes percent-encoded octets of unreserved characters.
[26] Fix | Delete
*
[27] Fix | Delete
* For consistency, percent-encoded octets in the ranges of ALPHA (%41–%5A and %61–%7A), DIGIT (%30–%39),
[28] Fix | Delete
* hyphen (%2D), period (%2E), underscore (%5F), or tilde (%7E) should not be created by URI producers and,
[29] Fix | Delete
* when found in a URI, should be decoded to their corresponding unreserved characters by URI normalizers.
[30] Fix | Delete
*
[31] Fix | Delete
* Example: http://example.org/%7Eusern%61me/ → http://example.org/~username/
[32] Fix | Delete
*/
[33] Fix | Delete
public const DECODE_UNRESERVED_CHARACTERS = 2;
[34] Fix | Delete
/**
[35] Fix | Delete
* Converts the empty path to "/" for http and https URIs.
[36] Fix | Delete
*
[37] Fix | Delete
* Example: http://example.org → http://example.org/
[38] Fix | Delete
*/
[39] Fix | Delete
public const CONVERT_EMPTY_PATH = 4;
[40] Fix | Delete
/**
[41] Fix | Delete
* Removes the default host of the given URI scheme from the URI.
[42] Fix | Delete
*
[43] Fix | Delete
* Only the "file" scheme defines the default host "localhost".
[44] Fix | Delete
* All of `file:/myfile`, `file:///myfile`, and `file://localhost/myfile`
[45] Fix | Delete
* are equivalent according to RFC 3986. The first format is not accepted
[46] Fix | Delete
* by PHPs stream functions and thus already normalized implicitly to the
[47] Fix | Delete
* second format in the Uri class. See `GuzzleHttp\Psr7\Uri::composeComponents`.
[48] Fix | Delete
*
[49] Fix | Delete
* Example: file://localhost/myfile → file:///myfile
[50] Fix | Delete
*/
[51] Fix | Delete
public const REMOVE_DEFAULT_HOST = 8;
[52] Fix | Delete
/**
[53] Fix | Delete
* Removes the default port of the given URI scheme from the URI.
[54] Fix | Delete
*
[55] Fix | Delete
* Example: http://example.org:80/ → http://example.org/
[56] Fix | Delete
*/
[57] Fix | Delete
public const REMOVE_DEFAULT_PORT = 16;
[58] Fix | Delete
/**
[59] Fix | Delete
* Removes unnecessary dot-segments.
[60] Fix | Delete
*
[61] Fix | Delete
* Dot-segments in relative-path references are not removed as it would
[62] Fix | Delete
* change the semantics of the URI reference.
[63] Fix | Delete
*
[64] Fix | Delete
* Example: http://example.org/../a/b/../c/./d.html → http://example.org/a/c/d.html
[65] Fix | Delete
*/
[66] Fix | Delete
public const REMOVE_DOT_SEGMENTS = 32;
[67] Fix | Delete
/**
[68] Fix | Delete
* Paths which include two or more adjacent slashes are converted to one.
[69] Fix | Delete
*
[70] Fix | Delete
* Webservers usually ignore duplicate slashes and treat those URIs equivalent.
[71] Fix | Delete
* But in theory those URIs do not need to be equivalent. So this normalization
[72] Fix | Delete
* may change the semantics. Encoded slashes (%2F) are not removed.
[73] Fix | Delete
*
[74] Fix | Delete
* Example: http://example.org//foo///bar.html → http://example.org/foo/bar.html
[75] Fix | Delete
*/
[76] Fix | Delete
public const REMOVE_DUPLICATE_SLASHES = 64;
[77] Fix | Delete
/**
[78] Fix | Delete
* Sort query parameters with their values in alphabetical order.
[79] Fix | Delete
*
[80] Fix | Delete
* However, the order of parameters in a URI may be significant (this is not defined by the standard).
[81] Fix | Delete
* So this normalization is not safe and may change the semantics of the URI.
[82] Fix | Delete
*
[83] Fix | Delete
* Example: ?lang=en&article=fred → ?article=fred&lang=en
[84] Fix | Delete
*
[85] Fix | Delete
* Note: The sorting is neither locale nor Unicode aware (the URI query does not get decoded at all) as the
[86] Fix | Delete
* purpose is to be able to compare URIs in a reproducible way, not to have the params sorted perfectly.
[87] Fix | Delete
*/
[88] Fix | Delete
public const SORT_QUERY_PARAMETERS = 128;
[89] Fix | Delete
/**
[90] Fix | Delete
* Returns a normalized URI.
[91] Fix | Delete
*
[92] Fix | Delete
* The scheme and host component are already normalized to lowercase per PSR-7 UriInterface.
[93] Fix | Delete
* This methods adds additional normalizations that can be configured with the $flags parameter.
[94] Fix | Delete
*
[95] Fix | Delete
* PSR-7 UriInterface cannot distinguish between an empty component and a missing component as
[96] Fix | Delete
* getQuery(), getFragment() etc. always return a string. This means the URIs "/?#" and "/" are
[97] Fix | Delete
* treated equivalent which is not necessarily true according to RFC 3986. But that difference
[98] Fix | Delete
* is highly uncommon in reality. So this potential normalization is implied in PSR-7 as well.
[99] Fix | Delete
*
[100] Fix | Delete
* @param UriInterface $uri The URI to normalize
[101] Fix | Delete
* @param int $flags A bitmask of normalizations to apply, see constants
[102] Fix | Delete
*
[103] Fix | Delete
* @see https://datatracker.ietf.org/doc/html/rfc3986#section-6.2
[104] Fix | Delete
*/
[105] Fix | Delete
public static function normalize(\YoastSEO_Vendor\Psr\Http\Message\UriInterface $uri, int $flags = self::PRESERVING_NORMALIZATIONS) : \YoastSEO_Vendor\Psr\Http\Message\UriInterface
[106] Fix | Delete
{
[107] Fix | Delete
if ($flags & self::CAPITALIZE_PERCENT_ENCODING) {
[108] Fix | Delete
$uri = self::capitalizePercentEncoding($uri);
[109] Fix | Delete
}
[110] Fix | Delete
if ($flags & self::DECODE_UNRESERVED_CHARACTERS) {
[111] Fix | Delete
$uri = self::decodeUnreservedCharacters($uri);
[112] Fix | Delete
}
[113] Fix | Delete
if ($flags & self::CONVERT_EMPTY_PATH && $uri->getPath() === '' && ($uri->getScheme() === 'http' || $uri->getScheme() === 'https')) {
[114] Fix | Delete
$uri = $uri->withPath('/');
[115] Fix | Delete
}
[116] Fix | Delete
if ($flags & self::REMOVE_DEFAULT_HOST && $uri->getScheme() === 'file' && $uri->getHost() === 'localhost') {
[117] Fix | Delete
$uri = $uri->withHost('');
[118] Fix | Delete
}
[119] Fix | Delete
if ($flags & self::REMOVE_DEFAULT_PORT && $uri->getPort() !== null && \YoastSEO_Vendor\GuzzleHttp\Psr7\Uri::isDefaultPort($uri)) {
[120] Fix | Delete
$uri = $uri->withPort(null);
[121] Fix | Delete
}
[122] Fix | Delete
if ($flags & self::REMOVE_DOT_SEGMENTS && !\YoastSEO_Vendor\GuzzleHttp\Psr7\Uri::isRelativePathReference($uri)) {
[123] Fix | Delete
$uri = $uri->withPath(\YoastSEO_Vendor\GuzzleHttp\Psr7\UriResolver::removeDotSegments($uri->getPath()));
[124] Fix | Delete
}
[125] Fix | Delete
if ($flags & self::REMOVE_DUPLICATE_SLASHES) {
[126] Fix | Delete
$uri = $uri->withPath(\preg_replace('#//++#', '/', $uri->getPath()));
[127] Fix | Delete
}
[128] Fix | Delete
if ($flags & self::SORT_QUERY_PARAMETERS && $uri->getQuery() !== '') {
[129] Fix | Delete
$queryKeyValues = \explode('&', $uri->getQuery());
[130] Fix | Delete
\sort($queryKeyValues);
[131] Fix | Delete
$uri = $uri->withQuery(\implode('&', $queryKeyValues));
[132] Fix | Delete
}
[133] Fix | Delete
return $uri;
[134] Fix | Delete
}
[135] Fix | Delete
/**
[136] Fix | Delete
* Whether two URIs can be considered equivalent.
[137] Fix | Delete
*
[138] Fix | Delete
* Both URIs are normalized automatically before comparison with the given $normalizations bitmask. The method also
[139] Fix | Delete
* accepts relative URI references and returns true when they are equivalent. This of course assumes they will be
[140] Fix | Delete
* resolved against the same base URI. If this is not the case, determination of equivalence or difference of
[141] Fix | Delete
* relative references does not mean anything.
[142] Fix | Delete
*
[143] Fix | Delete
* @param UriInterface $uri1 An URI to compare
[144] Fix | Delete
* @param UriInterface $uri2 An URI to compare
[145] Fix | Delete
* @param int $normalizations A bitmask of normalizations to apply, see constants
[146] Fix | Delete
*
[147] Fix | Delete
* @see https://datatracker.ietf.org/doc/html/rfc3986#section-6.1
[148] Fix | Delete
*/
[149] Fix | Delete
public static function isEquivalent(\YoastSEO_Vendor\Psr\Http\Message\UriInterface $uri1, \YoastSEO_Vendor\Psr\Http\Message\UriInterface $uri2, int $normalizations = self::PRESERVING_NORMALIZATIONS) : bool
[150] Fix | Delete
{
[151] Fix | Delete
return (string) self::normalize($uri1, $normalizations) === (string) self::normalize($uri2, $normalizations);
[152] Fix | Delete
}
[153] Fix | Delete
private static function capitalizePercentEncoding(\YoastSEO_Vendor\Psr\Http\Message\UriInterface $uri) : \YoastSEO_Vendor\Psr\Http\Message\UriInterface
[154] Fix | Delete
{
[155] Fix | Delete
$regex = '/(?:%[A-Fa-f0-9]{2})++/';
[156] Fix | Delete
$callback = function (array $match) : string {
[157] Fix | Delete
return \strtoupper($match[0]);
[158] Fix | Delete
};
[159] Fix | Delete
return $uri->withPath(\preg_replace_callback($regex, $callback, $uri->getPath()))->withQuery(\preg_replace_callback($regex, $callback, $uri->getQuery()));
[160] Fix | Delete
}
[161] Fix | Delete
private static function decodeUnreservedCharacters(\YoastSEO_Vendor\Psr\Http\Message\UriInterface $uri) : \YoastSEO_Vendor\Psr\Http\Message\UriInterface
[162] Fix | Delete
{
[163] Fix | Delete
$regex = '/%(?:2D|2E|5F|7E|3[0-9]|[46][1-9A-F]|[57][0-9A])/i';
[164] Fix | Delete
$callback = function (array $match) : string {
[165] Fix | Delete
return \rawurldecode($match[0]);
[166] Fix | Delete
};
[167] Fix | Delete
return $uri->withPath(\preg_replace_callback($regex, $callback, $uri->getPath()))->withQuery(\preg_replace_callback($regex, $callback, $uri->getQuery()));
[168] Fix | Delete
}
[169] Fix | Delete
private function __construct()
[170] Fix | Delete
{
[171] Fix | Delete
// cannot be instantiated
[172] Fix | Delete
}
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function