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