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