Cookie
3 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
3 years ago
RequestOptions.php
3 years ago
RetryMiddleware.php
3 years ago
TransferStats.php
3 years ago
UriTemplate.php
3 years ago
Utils.php
3 years ago
functions.php
3 years ago
functions_include.php
3 years ago
Utils.php
83 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPMailSMTP\Vendor\GuzzleHttp; |
| 4 | |
| 5 | use WPMailSMTP\Vendor\GuzzleHttp\Exception\InvalidArgumentException; |
| 6 | use WPMailSMTP\Vendor\Psr\Http\Message\UriInterface; |
| 7 | use WPMailSMTP\Vendor\Symfony\Polyfill\Intl\Idn\Idn; |
| 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) / 1000000000.0 : \microtime(\true); |
| 21 | } |
| 22 | /** |
| 23 | * @param int $options |
| 24 | * |
| 25 | * @return UriInterface |
| 26 | * @throws InvalidArgumentException |
| 27 | * |
| 28 | * @internal |
| 29 | */ |
| 30 | public static function idnUriConvert(\WPMailSMTP\Vendor\Psr\Http\Message\UriInterface $uri, $options = 0) |
| 31 | { |
| 32 | if ($uri->getHost()) { |
| 33 | $asciiHost = self::idnToAsci($uri->getHost(), $options, $info); |
| 34 | if ($asciiHost === \false) { |
| 35 | $errorBitSet = isset($info['errors']) ? $info['errors'] : 0; |
| 36 | $errorConstants = \array_filter(\array_keys(\get_defined_constants()), function ($name) { |
| 37 | return \substr($name, 0, 11) === 'IDNA_ERROR_'; |
| 38 | }); |
| 39 | $errors = []; |
| 40 | foreach ($errorConstants as $errorConstant) { |
| 41 | if ($errorBitSet & \constant($errorConstant)) { |
| 42 | $errors[] = $errorConstant; |
| 43 | } |
| 44 | } |
| 45 | $errorMessage = 'IDN conversion failed'; |
| 46 | if ($errors) { |
| 47 | $errorMessage .= ' (errors: ' . \implode(', ', $errors) . ')'; |
| 48 | } |
| 49 | throw new \WPMailSMTP\Vendor\GuzzleHttp\Exception\InvalidArgumentException($errorMessage); |
| 50 | } else { |
| 51 | if ($uri->getHost() !== $asciiHost) { |
| 52 | // Replace URI only if the ASCII version is different |
| 53 | $uri = $uri->withHost($asciiHost); |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | return $uri; |
| 58 | } |
| 59 | /** |
| 60 | * @param string $domain |
| 61 | * @param int $options |
| 62 | * @param array $info |
| 63 | * |
| 64 | * @return string|false |
| 65 | */ |
| 66 | private static function idnToAsci($domain, $options, &$info = []) |
| 67 | { |
| 68 | if (\preg_match('%^[ -~]+$%', $domain) === 1) { |
| 69 | return $domain; |
| 70 | } |
| 71 | if (\extension_loaded('intl') && \defined('INTL_IDNA_VARIANT_UTS46')) { |
| 72 | return \idn_to_ascii($domain, $options, \INTL_IDNA_VARIANT_UTS46, $info); |
| 73 | } |
| 74 | /* |
| 75 | * The Idn class is marked as @internal. Verify that class and method exists. |
| 76 | */ |
| 77 | if (\method_exists(\WPMailSMTP\Vendor\Symfony\Polyfill\Intl\Idn\Idn::class, 'idn_to_ascii')) { |
| 78 | return \WPMailSMTP\Vendor\Symfony\Polyfill\Intl\Idn\Idn::idn_to_ascii($domain, $options, \WPMailSMTP\Vendor\Symfony\Polyfill\Intl\Idn\Idn::INTL_IDNA_VARIANT_UTS46, $info); |
| 79 | } |
| 80 | throw new \RuntimeException('ext-intl or symfony/polyfill-intl-idn not loaded or too old'); |
| 81 | } |
| 82 | } |
| 83 |