PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
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 2 years ago Exception 3 years ago Handler 3 years ago Client.php 3 years ago ClientInterface.php 3 years ago HandlerStack.php 3 years ago MessageFormatter.php 3 years ago Middleware.php 3 years ago Pool.php 3 years ago PrepareBodyMiddleware.php 3 years ago RedirectMiddleware.php 2 years ago RequestOptions.php 5 years ago RetryMiddleware.php 3 years ago TransferStats.php 3 years ago UriTemplate.php 5 years ago Utils.php 3 years ago functions.php 5 years ago functions_include.php 5 years ago
Utils.php
93 lines
1 <?php
2 namespace AmeliaGuzzleHttp;
3
4 use AmeliaGuzzleHttp\Exception\InvalidArgumentException;
5 use AmeliaPsr\Http\Message\UriInterface;
6 use Symfony\Polyfill\Intl\Idn\Idn;
7
8 final class Utils
9 {
10 /**
11 * Wrapper for the hrtime() or microtime() functions
12 * (depending on the PHP version, one of the two is used)
13 *
14 * @return float|mixed UNIX timestamp
15 *
16 * @internal
17 */
18 public static function currentTime()
19 {
20 return function_exists('hrtime') ? hrtime(true) / 1e9 : microtime(true);
21 }
22
23 /**
24 * @param int $options
25 *
26 * @return UriInterface
27 * @throws InvalidArgumentException
28 *
29 * @internal
30 */
31 public static function idnUriConvert(UriInterface $uri, $options = 0)
32 {
33 if ($uri->getHost()) {
34 $asciiHost = self::idnToAsci($uri->getHost(), $options, $info);
35 if ($asciiHost === false) {
36 $errorBitSet = isset($info['errors']) ? $info['errors'] : 0;
37
38 $errorConstants = array_filter(array_keys(get_defined_constants()), function ($name) {
39 return substr($name, 0, 11) === 'IDNA_ERROR_';
40 });
41
42 $errors = [];
43 foreach ($errorConstants as $errorConstant) {
44 if ($errorBitSet & constant($errorConstant)) {
45 $errors[] = $errorConstant;
46 }
47 }
48
49 $errorMessage = 'IDN conversion failed';
50 if ($errors) {
51 $errorMessage .= ' (errors: ' . implode(', ', $errors) . ')';
52 }
53
54 throw new InvalidArgumentException($errorMessage);
55 } else {
56 if ($uri->getHost() !== $asciiHost) {
57 // Replace URI only if the ASCII version is different
58 $uri = $uri->withHost($asciiHost);
59 }
60 }
61 }
62
63 return $uri;
64 }
65
66 /**
67 * @param string $domain
68 * @param int $options
69 * @param array $info
70 *
71 * @return string|false
72 */
73 private static function idnToAsci($domain, $options, &$info = [])
74 {
75 if (\preg_match('%^[ -~]+$%', $domain) === 1) {
76 return $domain;
77 }
78
79 if (\extension_loaded('intl') && defined('INTL_IDNA_VARIANT_UTS46')) {
80 return \idn_to_ascii($domain, $options, INTL_IDNA_VARIANT_UTS46, $info);
81 }
82
83 /*
84 * The Idn class is marked as @internal. Verify that class and method exists.
85 */
86 if (method_exists(Idn::class, 'idn_to_ascii')) {
87 return Idn::idn_to_ascii($domain, $options, Idn::INTL_IDNA_VARIANT_UTS46, $info);
88 }
89
90 throw new \RuntimeException('ext-intl or symfony/polyfill-intl-idn not loaded or too old');
91 }
92 }
93