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.../guzzle/src
File: Utils.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace YoastSEO_Vendor\GuzzleHttp;
[2] Fix | Delete
[3] Fix | Delete
use YoastSEO_Vendor\GuzzleHttp\Exception\InvalidArgumentException;
[4] Fix | Delete
use YoastSEO_Vendor\GuzzleHttp\Handler\CurlHandler;
[5] Fix | Delete
use YoastSEO_Vendor\GuzzleHttp\Handler\CurlMultiHandler;
[6] Fix | Delete
use YoastSEO_Vendor\GuzzleHttp\Handler\Proxy;
[7] Fix | Delete
use YoastSEO_Vendor\GuzzleHttp\Handler\StreamHandler;
[8] Fix | Delete
use YoastSEO_Vendor\Psr\Http\Message\UriInterface;
[9] Fix | Delete
final class Utils
[10] Fix | Delete
{
[11] Fix | Delete
/**
[12] Fix | Delete
* Debug function used to describe the provided value type and class.
[13] Fix | Delete
*
[14] Fix | Delete
* @param mixed $input
[15] Fix | Delete
*
[16] Fix | Delete
* @return string Returns a string containing the type of the variable and
[17] Fix | Delete
* if a class is provided, the class name.
[18] Fix | Delete
*/
[19] Fix | Delete
public static function describeType($input) : string
[20] Fix | Delete
{
[21] Fix | Delete
switch (\gettype($input)) {
[22] Fix | Delete
case 'object':
[23] Fix | Delete
return 'object(' . \get_class($input) . ')';
[24] Fix | Delete
case 'array':
[25] Fix | Delete
return 'array(' . \count($input) . ')';
[26] Fix | Delete
default:
[27] Fix | Delete
\ob_start();
[28] Fix | Delete
\var_dump($input);
[29] Fix | Delete
// normalize float vs double
[30] Fix | Delete
/** @var string $varDumpContent */
[31] Fix | Delete
$varDumpContent = \ob_get_clean();
[32] Fix | Delete
return \str_replace('double(', 'float(', \rtrim($varDumpContent));
[33] Fix | Delete
}
[34] Fix | Delete
}
[35] Fix | Delete
/**
[36] Fix | Delete
* Parses an array of header lines into an associative array of headers.
[37] Fix | Delete
*
[38] Fix | Delete
* @param iterable $lines Header lines array of strings in the following
[39] Fix | Delete
* format: "Name: Value"
[40] Fix | Delete
*/
[41] Fix | Delete
public static function headersFromLines(iterable $lines) : array
[42] Fix | Delete
{
[43] Fix | Delete
$headers = [];
[44] Fix | Delete
foreach ($lines as $line) {
[45] Fix | Delete
$parts = \explode(':', $line, 2);
[46] Fix | Delete
$headers[\trim($parts[0])][] = isset($parts[1]) ? \trim($parts[1]) : null;
[47] Fix | Delete
}
[48] Fix | Delete
return $headers;
[49] Fix | Delete
}
[50] Fix | Delete
/**
[51] Fix | Delete
* Returns a debug stream based on the provided variable.
[52] Fix | Delete
*
[53] Fix | Delete
* @param mixed $value Optional value
[54] Fix | Delete
*
[55] Fix | Delete
* @return resource
[56] Fix | Delete
*/
[57] Fix | Delete
public static function debugResource($value = null)
[58] Fix | Delete
{
[59] Fix | Delete
if (\is_resource($value)) {
[60] Fix | Delete
return $value;
[61] Fix | Delete
}
[62] Fix | Delete
if (\defined('STDOUT')) {
[63] Fix | Delete
return \STDOUT;
[64] Fix | Delete
}
[65] Fix | Delete
return \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::tryFopen('php://output', 'w');
[66] Fix | Delete
}
[67] Fix | Delete
/**
[68] Fix | Delete
* Chooses and creates a default handler to use based on the environment.
[69] Fix | Delete
*
[70] Fix | Delete
* The returned handler is not wrapped by any default middlewares.
[71] Fix | Delete
*
[72] Fix | Delete
* @return callable(\Psr\Http\Message\RequestInterface, array): \GuzzleHttp\Promise\PromiseInterface Returns the best handler for the given system.
[73] Fix | Delete
*
[74] Fix | Delete
* @throws \RuntimeException if no viable Handler is available.
[75] Fix | Delete
*/
[76] Fix | Delete
public static function chooseHandler() : callable
[77] Fix | Delete
{
[78] Fix | Delete
$handler = null;
[79] Fix | Delete
if (\defined('CURLOPT_CUSTOMREQUEST')) {
[80] Fix | Delete
if (\function_exists('curl_multi_exec') && \function_exists('curl_exec')) {
[81] Fix | Delete
$handler = \YoastSEO_Vendor\GuzzleHttp\Handler\Proxy::wrapSync(new \YoastSEO_Vendor\GuzzleHttp\Handler\CurlMultiHandler(), new \YoastSEO_Vendor\GuzzleHttp\Handler\CurlHandler());
[82] Fix | Delete
} elseif (\function_exists('curl_exec')) {
[83] Fix | Delete
$handler = new \YoastSEO_Vendor\GuzzleHttp\Handler\CurlHandler();
[84] Fix | Delete
} elseif (\function_exists('curl_multi_exec')) {
[85] Fix | Delete
$handler = new \YoastSEO_Vendor\GuzzleHttp\Handler\CurlMultiHandler();
[86] Fix | Delete
}
[87] Fix | Delete
}
[88] Fix | Delete
if (\ini_get('allow_url_fopen')) {
[89] Fix | Delete
$handler = $handler ? \YoastSEO_Vendor\GuzzleHttp\Handler\Proxy::wrapStreaming($handler, new \YoastSEO_Vendor\GuzzleHttp\Handler\StreamHandler()) : new \YoastSEO_Vendor\GuzzleHttp\Handler\StreamHandler();
[90] Fix | Delete
} elseif (!$handler) {
[91] Fix | Delete
throw new \RuntimeException('GuzzleHttp requires cURL, the allow_url_fopen ini setting, or a custom HTTP handler.');
[92] Fix | Delete
}
[93] Fix | Delete
return $handler;
[94] Fix | Delete
}
[95] Fix | Delete
/**
[96] Fix | Delete
* Get the default User-Agent string to use with Guzzle.
[97] Fix | Delete
*/
[98] Fix | Delete
public static function defaultUserAgent() : string
[99] Fix | Delete
{
[100] Fix | Delete
return \sprintf('GuzzleHttp/%d', \YoastSEO_Vendor\GuzzleHttp\ClientInterface::MAJOR_VERSION);
[101] Fix | Delete
}
[102] Fix | Delete
/**
[103] Fix | Delete
* Returns the default cacert bundle for the current system.
[104] Fix | Delete
*
[105] Fix | Delete
* First, the openssl.cafile and curl.cainfo php.ini settings are checked.
[106] Fix | Delete
* If those settings are not configured, then the common locations for
[107] Fix | Delete
* bundles found on Red Hat, CentOS, Fedora, Ubuntu, Debian, FreeBSD, OS X
[108] Fix | Delete
* and Windows are checked. If any of these file locations are found on
[109] Fix | Delete
* disk, they will be utilized.
[110] Fix | Delete
*
[111] Fix | Delete
* Note: the result of this function is cached for subsequent calls.
[112] Fix | Delete
*
[113] Fix | Delete
* @throws \RuntimeException if no bundle can be found.
[114] Fix | Delete
*
[115] Fix | Delete
* @deprecated Utils::defaultCaBundle will be removed in guzzlehttp/guzzle:8.0. This method is not needed in PHP 5.6+.
[116] Fix | Delete
*/
[117] Fix | Delete
public static function defaultCaBundle() : string
[118] Fix | Delete
{
[119] Fix | Delete
static $cached = null;
[120] Fix | Delete
static $cafiles = [
[121] Fix | Delete
// Red Hat, CentOS, Fedora (provided by the ca-certificates package)
[122] Fix | Delete
'/etc/pki/tls/certs/ca-bundle.crt',
[123] Fix | Delete
// Ubuntu, Debian (provided by the ca-certificates package)
[124] Fix | Delete
'/etc/ssl/certs/ca-certificates.crt',
[125] Fix | Delete
// FreeBSD (provided by the ca_root_nss package)
[126] Fix | Delete
'/usr/local/share/certs/ca-root-nss.crt',
[127] Fix | Delete
// SLES 12 (provided by the ca-certificates package)
[128] Fix | Delete
'/var/lib/ca-certificates/ca-bundle.pem',
[129] Fix | Delete
// OS X provided by homebrew (using the default path)
[130] Fix | Delete
'/usr/local/etc/openssl/cert.pem',
[131] Fix | Delete
// Google app engine
[132] Fix | Delete
'/etc/ca-certificates.crt',
[133] Fix | Delete
// Windows?
[134] Fix | Delete
'C:\\windows\\system32\\curl-ca-bundle.crt',
[135] Fix | Delete
'C:\\windows\\curl-ca-bundle.crt',
[136] Fix | Delete
];
[137] Fix | Delete
if ($cached) {
[138] Fix | Delete
return $cached;
[139] Fix | Delete
}
[140] Fix | Delete
if ($ca = \ini_get('openssl.cafile')) {
[141] Fix | Delete
return $cached = $ca;
[142] Fix | Delete
}
[143] Fix | Delete
if ($ca = \ini_get('curl.cainfo')) {
[144] Fix | Delete
return $cached = $ca;
[145] Fix | Delete
}
[146] Fix | Delete
foreach ($cafiles as $filename) {
[147] Fix | Delete
if (\file_exists($filename)) {
[148] Fix | Delete
return $cached = $filename;
[149] Fix | Delete
}
[150] Fix | Delete
}
[151] Fix | Delete
throw new \RuntimeException(<<<EOT
[152] Fix | Delete
No system CA bundle could be found in any of the the common system locations.
[153] Fix | Delete
PHP versions earlier than 5.6 are not properly configured to use the system's
[154] Fix | Delete
CA bundle by default. In order to verify peer certificates, you will need to
[155] Fix | Delete
supply the path on disk to a certificate bundle to the 'verify' request
[156] Fix | Delete
option: https://docs.guzzlephp.org/en/latest/request-options.html#verify. If
[157] Fix | Delete
you do not need a specific certificate bundle, then Mozilla provides a commonly
[158] Fix | Delete
used CA bundle which can be downloaded here (provided by the maintainer of
[159] Fix | Delete
cURL): https://curl.haxx.se/ca/cacert.pem. Once you have a CA bundle available
[160] Fix | Delete
on disk, you can set the 'openssl.cafile' PHP ini setting to point to the path
[161] Fix | Delete
to the file, allowing you to omit the 'verify' request option. See
[162] Fix | Delete
https://curl.haxx.se/docs/sslcerts.html for more information.
[163] Fix | Delete
EOT
[164] Fix | Delete
);
[165] Fix | Delete
}
[166] Fix | Delete
/**
[167] Fix | Delete
* Creates an associative array of lowercase header names to the actual
[168] Fix | Delete
* header casing.
[169] Fix | Delete
*/
[170] Fix | Delete
public static function normalizeHeaderKeys(array $headers) : array
[171] Fix | Delete
{
[172] Fix | Delete
$result = [];
[173] Fix | Delete
foreach (\array_keys($headers) as $key) {
[174] Fix | Delete
$result[\strtolower($key)] = $key;
[175] Fix | Delete
}
[176] Fix | Delete
return $result;
[177] Fix | Delete
}
[178] Fix | Delete
/**
[179] Fix | Delete
* Returns true if the provided host matches any of the no proxy areas.
[180] Fix | Delete
*
[181] Fix | Delete
* This method will strip a port from the host if it is present. Each pattern
[182] Fix | Delete
* can be matched with an exact match (e.g., "foo.com" == "foo.com") or a
[183] Fix | Delete
* partial match: (e.g., "foo.com" == "baz.foo.com" and ".foo.com" ==
[184] Fix | Delete
* "baz.foo.com", but ".foo.com" != "foo.com").
[185] Fix | Delete
*
[186] Fix | Delete
* Areas are matched in the following cases:
[187] Fix | Delete
* 1. "*" (without quotes) always matches any hosts.
[188] Fix | Delete
* 2. An exact match.
[189] Fix | Delete
* 3. The area starts with "." and the area is the last part of the host. e.g.
[190] Fix | Delete
* '.mit.edu' will match any host that ends with '.mit.edu'.
[191] Fix | Delete
*
[192] Fix | Delete
* @param string $host Host to check against the patterns.
[193] Fix | Delete
* @param string[] $noProxyArray An array of host patterns.
[194] Fix | Delete
*
[195] Fix | Delete
* @throws InvalidArgumentException
[196] Fix | Delete
*/
[197] Fix | Delete
public static function isHostInNoProxy(string $host, array $noProxyArray) : bool
[198] Fix | Delete
{
[199] Fix | Delete
if (\strlen($host) === 0) {
[200] Fix | Delete
throw new \YoastSEO_Vendor\GuzzleHttp\Exception\InvalidArgumentException('Empty host provided');
[201] Fix | Delete
}
[202] Fix | Delete
// Strip port if present.
[203] Fix | Delete
[$host] = \explode(':', $host, 2);
[204] Fix | Delete
foreach ($noProxyArray as $area) {
[205] Fix | Delete
// Always match on wildcards.
[206] Fix | Delete
if ($area === '*') {
[207] Fix | Delete
return \true;
[208] Fix | Delete
}
[209] Fix | Delete
if (empty($area)) {
[210] Fix | Delete
// Don't match on empty values.
[211] Fix | Delete
continue;
[212] Fix | Delete
}
[213] Fix | Delete
if ($area === $host) {
[214] Fix | Delete
// Exact matches.
[215] Fix | Delete
return \true;
[216] Fix | Delete
}
[217] Fix | Delete
// Special match if the area when prefixed with ".". Remove any
[218] Fix | Delete
// existing leading "." and add a new leading ".".
[219] Fix | Delete
$area = '.' . \ltrim($area, '.');
[220] Fix | Delete
if (\substr($host, -\strlen($area)) === $area) {
[221] Fix | Delete
return \true;
[222] Fix | Delete
}
[223] Fix | Delete
}
[224] Fix | Delete
return \false;
[225] Fix | Delete
}
[226] Fix | Delete
/**
[227] Fix | Delete
* Wrapper for json_decode that throws when an error occurs.
[228] Fix | Delete
*
[229] Fix | Delete
* @param string $json JSON data to parse
[230] Fix | Delete
* @param bool $assoc When true, returned objects will be converted
[231] Fix | Delete
* into associative arrays.
[232] Fix | Delete
* @param int $depth User specified recursion depth.
[233] Fix | Delete
* @param int $options Bitmask of JSON decode options.
[234] Fix | Delete
*
[235] Fix | Delete
* @return object|array|string|int|float|bool|null
[236] Fix | Delete
*
[237] Fix | Delete
* @throws InvalidArgumentException if the JSON cannot be decoded.
[238] Fix | Delete
*
[239] Fix | Delete
* @see https://www.php.net/manual/en/function.json-decode.php
[240] Fix | Delete
*/
[241] Fix | Delete
public static function jsonDecode(string $json, bool $assoc = \false, int $depth = 512, int $options = 0)
[242] Fix | Delete
{
[243] Fix | Delete
$data = \json_decode($json, $assoc, $depth, $options);
[244] Fix | Delete
if (\JSON_ERROR_NONE !== \json_last_error()) {
[245] Fix | Delete
throw new \YoastSEO_Vendor\GuzzleHttp\Exception\InvalidArgumentException('json_decode error: ' . \json_last_error_msg());
[246] Fix | Delete
}
[247] Fix | Delete
return $data;
[248] Fix | Delete
}
[249] Fix | Delete
/**
[250] Fix | Delete
* Wrapper for JSON encoding that throws when an error occurs.
[251] Fix | Delete
*
[252] Fix | Delete
* @param mixed $value The value being encoded
[253] Fix | Delete
* @param int $options JSON encode option bitmask
[254] Fix | Delete
* @param int $depth Set the maximum depth. Must be greater than zero.
[255] Fix | Delete
*
[256] Fix | Delete
* @throws InvalidArgumentException if the JSON cannot be encoded.
[257] Fix | Delete
*
[258] Fix | Delete
* @see https://www.php.net/manual/en/function.json-encode.php
[259] Fix | Delete
*/
[260] Fix | Delete
public static function jsonEncode($value, int $options = 0, int $depth = 512) : string
[261] Fix | Delete
{
[262] Fix | Delete
$json = \json_encode($value, $options, $depth);
[263] Fix | Delete
if (\JSON_ERROR_NONE !== \json_last_error()) {
[264] Fix | Delete
throw new \YoastSEO_Vendor\GuzzleHttp\Exception\InvalidArgumentException('json_encode error: ' . \json_last_error_msg());
[265] Fix | Delete
}
[266] Fix | Delete
/** @var string */
[267] Fix | Delete
return $json;
[268] Fix | Delete
}
[269] Fix | Delete
/**
[270] Fix | Delete
* Wrapper for the hrtime() or microtime() functions
[271] Fix | Delete
* (depending on the PHP version, one of the two is used)
[272] Fix | Delete
*
[273] Fix | Delete
* @return float UNIX timestamp
[274] Fix | Delete
*
[275] Fix | Delete
* @internal
[276] Fix | Delete
*/
[277] Fix | Delete
public static function currentTime() : float
[278] Fix | Delete
{
[279] Fix | Delete
return (float) \function_exists('hrtime') ? \hrtime(\true) / 1000000000.0 : \microtime(\true);
[280] Fix | Delete
}
[281] Fix | Delete
/**
[282] Fix | Delete
* @throws InvalidArgumentException
[283] Fix | Delete
*
[284] Fix | Delete
* @internal
[285] Fix | Delete
*/
[286] Fix | Delete
public static function idnUriConvert(\YoastSEO_Vendor\Psr\Http\Message\UriInterface $uri, int $options = 0) : \YoastSEO_Vendor\Psr\Http\Message\UriInterface
[287] Fix | Delete
{
[288] Fix | Delete
if ($uri->getHost()) {
[289] Fix | Delete
$asciiHost = self::idnToAsci($uri->getHost(), $options, $info);
[290] Fix | Delete
if ($asciiHost === \false) {
[291] Fix | Delete
$errorBitSet = $info['errors'] ?? 0;
[292] Fix | Delete
$errorConstants = \array_filter(\array_keys(\get_defined_constants()), static function (string $name) : bool {
[293] Fix | Delete
return \substr($name, 0, 11) === 'IDNA_ERROR_';
[294] Fix | Delete
});
[295] Fix | Delete
$errors = [];
[296] Fix | Delete
foreach ($errorConstants as $errorConstant) {
[297] Fix | Delete
if ($errorBitSet & \constant($errorConstant)) {
[298] Fix | Delete
$errors[] = $errorConstant;
[299] Fix | Delete
}
[300] Fix | Delete
}
[301] Fix | Delete
$errorMessage = 'IDN conversion failed';
[302] Fix | Delete
if ($errors) {
[303] Fix | Delete
$errorMessage .= ' (errors: ' . \implode(', ', $errors) . ')';
[304] Fix | Delete
}
[305] Fix | Delete
throw new \YoastSEO_Vendor\GuzzleHttp\Exception\InvalidArgumentException($errorMessage);
[306] Fix | Delete
}
[307] Fix | Delete
if ($uri->getHost() !== $asciiHost) {
[308] Fix | Delete
// Replace URI only if the ASCII version is different
[309] Fix | Delete
$uri = $uri->withHost($asciiHost);
[310] Fix | Delete
}
[311] Fix | Delete
}
[312] Fix | Delete
return $uri;
[313] Fix | Delete
}
[314] Fix | Delete
/**
[315] Fix | Delete
* @internal
[316] Fix | Delete
*/
[317] Fix | Delete
public static function getenv(string $name) : ?string
[318] Fix | Delete
{
[319] Fix | Delete
if (isset($_SERVER[$name])) {
[320] Fix | Delete
return (string) $_SERVER[$name];
[321] Fix | Delete
}
[322] Fix | Delete
if (\PHP_SAPI === 'cli' && ($value = \getenv($name)) !== \false && $value !== null) {
[323] Fix | Delete
return (string) $value;
[324] Fix | Delete
}
[325] Fix | Delete
return null;
[326] Fix | Delete
}
[327] Fix | Delete
/**
[328] Fix | Delete
* @return string|false
[329] Fix | Delete
*/
[330] Fix | Delete
private static function idnToAsci(string $domain, int $options, ?array &$info = [])
[331] Fix | Delete
{
[332] Fix | Delete
if (\function_exists('idn_to_ascii') && \defined('INTL_IDNA_VARIANT_UTS46')) {
[333] Fix | Delete
return \idn_to_ascii($domain, $options, \INTL_IDNA_VARIANT_UTS46, $info);
[334] Fix | Delete
}
[335] Fix | Delete
throw new \Error('ext-idn or symfony/polyfill-intl-idn not loaded or too old');
[336] Fix | Delete
}
[337] Fix | Delete
}
[338] Fix | Delete
[339] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function