← All changes
|
includes/sdk/google/guzzlehttp/guzzle/src/Utils.php
+27
-27
1.2.0
→
1.4.2
View file →
| @@ -1,14 +1,14 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -namespace Dudlewebs\WPMCS\GuzzleHttp; | |
| 3 | +namespace Dudlewebs\WPMCS\GCP\GuzzleHttp; | |
| 4 | 4 | |
| 5 | -use Dudlewebs\WPMCS\GuzzleHttp\Exception\InvalidArgumentException; | |
| 6 | -use Dudlewebs\WPMCS\GuzzleHttp\Handler\CurlHandler; | |
| 7 | -use Dudlewebs\WPMCS\GuzzleHttp\Handler\CurlMultiHandler; | |
| 8 | -use Dudlewebs\WPMCS\GuzzleHttp\Handler\Proxy; | |
| 9 | -use Dudlewebs\WPMCS\GuzzleHttp\Handler\StreamHandler; | |
| 10 | -use Dudlewebs\WPMCS\Psr\Http\Message\UriInterface; | |
| 5 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Exception\InvalidArgumentException; | |
| 6 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Handler\CurlHandler; | |
| 7 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Handler\CurlMultiHandler; | |
| 8 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Handler\Proxy; | |
| 9 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Handler\StreamHandler; | |
| 10 | +use Dudlewebs\WPMCS\GCP\Psr\Http\Message\UriInterface; | |
| 11 | 11 | final class Utils |
| 12 | 12 | { |
| 13 | 13 | /** |
| 14 | 14 | * Debug function used to describe the provided value type and class. |
| @@ -17,9 +17,9 @@ | ||
| 17 | 17 | * |
| 18 | 18 | * @return string Returns a string containing the type of the variable and |
| 19 | 19 | * if a class is provided, the class name. |
| 20 | 20 | */ |
| 21 | - public static function describeType($input): string | |
| 21 | + public static function describeType($input) : string | |
| 22 | 22 | { |
| 23 | 23 | switch (\gettype($input)) { |
| 24 | 24 | case 'object': |
| 25 | 25 | return 'object(' . \get_class($input) . ')'; |
| @@ -39,9 +39,9 @@ | ||
| 39 | 39 | * |
| 40 | 40 | * @param iterable $lines Header lines array of strings in the following |
| 41 | 41 | * format: "Name: Value" |
| 42 | 42 | */ |
| 43 | - public static function headersFromLines(iterable $lines): array | |
| 43 | + public static function headersFromLines(iterable $lines) : array | |
| 44 | 44 | { |
| 45 | 45 | $headers = []; |
| 46 | 46 | foreach ($lines as $line) { |
| 47 | 47 | $parts = \explode(':', $line, 2); |
| @@ -70,16 +70,16 @@ | ||
| 70 | 70 | * Chooses and creates a default handler to use based on the environment. |
| 71 | 71 | * |
| 72 | 72 | * The returned handler is not wrapped by any default middlewares. |
| 73 | 73 | * |
| 74 | - * @return callable(\Psr\Http\Message\RequestInterface, array): \GuzzleHttp\Promise\PromiseInterface Returns the best handler for the given system. | |
| 74 | + * @return callable(\Psr\Http\Message\RequestInterface, array): Promise\PromiseInterface Returns the best handler for the given system. | |
| 75 | 75 | * |
| 76 | 76 | * @throws \RuntimeException if no viable Handler is available. |
| 77 | 77 | */ |
| 78 | - public static function chooseHandler(): callable | |
| 78 | + public static function chooseHandler() : callable | |
| 79 | 79 | { |
| 80 | 80 | $handler = null; |
| 81 | - if (\defined('CURLOPT_CUSTOMREQUEST') && \function_exists('curl_version') && version_compare(curl_version()['version'], '7.21.2') >= 0) { | |
| 81 | + if (\defined('CURLOPT_CUSTOMREQUEST') && \function_exists('curl_version') && \version_compare(\curl_version()['version'], '7.21.2') >= 0) { | |
| 82 | 82 | if (\function_exists('curl_multi_exec') && \function_exists('curl_exec')) { |
| 83 | 83 | $handler = Proxy::wrapSync(new CurlMultiHandler(), new CurlHandler()); |
| 84 | 84 | } elseif (\function_exists('curl_exec')) { |
| 85 | 85 | $handler = new CurlHandler(); |
| @@ -96,11 +96,11 @@ | ||
| 96 | 96 | } |
| 97 | 97 | /** |
| 98 | 98 | * Get the default User-Agent string to use with Guzzle. |
| 99 | 99 | */ |
| 100 | - public static function defaultUserAgent(): string | |
| 100 | + public static function defaultUserAgent() : string | |
| 101 | 101 | { |
| 102 | - return sprintf('GuzzleHttp/%d', ClientInterface::MAJOR_VERSION); | |
| 102 | + return \sprintf('GuzzleHttp/%d', ClientInterface::MAJOR_VERSION); | |
| 103 | 103 | } |
| 104 | 104 | /** |
| 105 | 105 | * Returns the default cacert bundle for the current system. |
| 106 | 106 | * |
| @@ -115,9 +115,9 @@ | ||
| 115 | 115 | * @throws \RuntimeException if no bundle can be found. |
| 116 | 116 | * |
| 117 | 117 | * @deprecated Utils::defaultCaBundle will be removed in guzzlehttp/guzzle:8.0. This method is not needed in PHP 5.6+. |
| 118 | 118 | */ |
| 119 | - public static function defaultCaBundle(): string | |
| 119 | + public static function defaultCaBundle() : string | |
| 120 | 120 | { |
| 121 | 121 | static $cached = null; |
| 122 | 122 | static $cafiles = [ |
| 123 | 123 | // Red Hat, CentOS, Fedora (provided by the ca-certificates package) |
| @@ -132,10 +132,10 @@ | ||
| 132 | 132 | '/usr/local/etc/openssl/cert.pem', |
| 133 | 133 | // Google app engine |
| 134 | 134 | '/etc/ca-certificates.crt', |
| 135 | 135 | // Windows? |
| 136 | - 'C:\windows\system32\curl-ca-bundle.crt', | |
| 137 | - 'C:\windows\curl-ca-bundle.crt', | |
| 136 | + 'C:\\windows\\system32\\curl-ca-bundle.crt', | |
| 137 | + 'C:\\windows\\curl-ca-bundle.crt', | |
| 138 | 138 | ]; |
| 139 | 139 | if ($cached) { |
| 140 | 140 | return $cached; |
| 141 | 141 | } |
| @@ -168,9 +168,9 @@ | ||
| 168 | 168 | /** |
| 169 | 169 | * Creates an associative array of lowercase header names to the actual |
| 170 | 170 | * header casing. |
| 171 | 171 | */ |
| 172 | - public static function normalizeHeaderKeys(array $headers): array | |
| 172 | + public static function normalizeHeaderKeys(array $headers) : array | |
| 173 | 173 | { |
| 174 | 174 | $result = []; |
| 175 | 175 | foreach (\array_keys($headers) as $key) { |
| 176 | 176 | $result[\strtolower($key)] = $key; |
| @@ -195,9 +195,9 @@ | ||
| 195 | 195 | * @param string[] $noProxyArray An array of host patterns. |
| 196 | 196 | * |
| 197 | 197 | * @throws InvalidArgumentException |
| 198 | 198 | */ |
| 199 | - public static function isHostInNoProxy(string $host, array $noProxyArray): bool | |
| 199 | + public static function isHostInNoProxy(string $host, array $noProxyArray) : bool | |
| 200 | 200 | { |
| 201 | 201 | if (\strlen($host) === 0) { |
| 202 | 202 | throw new InvalidArgumentException('Empty host provided'); |
| 203 | 203 | } |
| @@ -258,9 +258,9 @@ | ||
| 258 | 258 | * @throws InvalidArgumentException if the JSON cannot be encoded. |
| 259 | 259 | * |
| 260 | 260 | * @see https://www.php.net/manual/en/function.json-encode.php |
| 261 | 261 | */ |
| 262 | - public static function jsonEncode($value, int $options = 0, int $depth = 512): string | |
| 262 | + public static function jsonEncode($value, int $options = 0, int $depth = 512) : string | |
| 263 | 263 | { |
| 264 | 264 | $json = \json_encode($value, $options, $depth); |
| 265 | 265 | if (\JSON_ERROR_NONE !== \json_last_error()) { |
| 266 | 266 | throw new InvalidArgumentException('json_encode error: ' . \json_last_error_msg()); |
| @@ -275,9 +275,9 @@ | ||
| 275 | 275 | * @return float UNIX timestamp |
| 276 | 276 | * |
| 277 | 277 | * @internal |
| 278 | 278 | */ |
| 279 | - public static function currentTime(): float | |
| 279 | + public static function currentTime() : float | |
| 280 | 280 | { |
| 281 | 281 | return (float) \function_exists('hrtime') ? \hrtime(\true) / 1000000000.0 : \microtime(\true); |
| 282 | 282 | } |
| 283 | 283 | /** |
| @@ -284,26 +284,26 @@ | ||
| 284 | 284 | * @throws InvalidArgumentException |
| 285 | 285 | * |
| 286 | 286 | * @internal |
| 287 | 287 | */ |
| 288 | - public static function idnUriConvert(UriInterface $uri, int $options = 0): UriInterface | |
| 288 | + public static function idnUriConvert(UriInterface $uri, int $options = 0) : UriInterface | |
| 289 | 289 | { |
| 290 | 290 | if ($uri->getHost()) { |
| 291 | 291 | $asciiHost = self::idnToAsci($uri->getHost(), $options, $info); |
| 292 | 292 | if ($asciiHost === \false) { |
| 293 | 293 | $errorBitSet = $info['errors'] ?? 0; |
| 294 | - $errorConstants = array_filter(array_keys(get_defined_constants()), static function (string $name): bool { | |
| 295 | - return substr($name, 0, 11) === 'IDNA_ERROR_'; | |
| 294 | + $errorConstants = \array_filter(\array_keys(\get_defined_constants()), static function (string $name) : bool { | |
| 295 | + return \substr($name, 0, 11) === 'IDNA_ERROR_'; | |
| 296 | 296 | }); |
| 297 | 297 | $errors = []; |
| 298 | 298 | foreach ($errorConstants as $errorConstant) { |
| 299 | - if ($errorBitSet & constant($errorConstant)) { | |
| 299 | + if ($errorBitSet & \constant($errorConstant)) { | |
| 300 | 300 | $errors[] = $errorConstant; |
| 301 | 301 | } |
| 302 | 302 | } |
| 303 | 303 | $errorMessage = 'IDN conversion failed'; |
| 304 | 304 | if ($errors) { |
| 305 | - $errorMessage .= ' (errors: ' . implode(', ', $errors) . ')'; | |
| 305 | + $errorMessage .= ' (errors: ' . \implode(', ', $errors) . ')'; | |
| 306 | 306 | } |
| 307 | 307 | throw new InvalidArgumentException($errorMessage); |
| 308 | 308 | } |
| 309 | 309 | if ($uri->getHost() !== $asciiHost) { |
| @@ -315,9 +315,9 @@ | ||
| 315 | 315 | } |
| 316 | 316 | /** |
| 317 | 317 | * @internal |
| 318 | 318 | */ |
| 319 | - public static function getenv(string $name): ?string | |
| 319 | + public static function getenv(string $name) : ?string | |
| 320 | 320 | { |
| 321 | 321 | if (isset($_SERVER[$name])) { |
| 322 | 322 | return (string) $_SERVER[$name]; |
| 323 | 323 | } |