PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 19.0
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v19.0
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / vendor_prefixed / guzzlehttp / guzzle / src / Utils.php

Utils.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 19.0, at vendor_prefixed/guzzlehttp/guzzle/src/Utils.php

83 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YoastSEO_Vendor\GuzzleHttp;
4
5 use YoastSEO_Vendor\GuzzleHttp\Exception\InvalidArgumentException;
6 use YoastSEO_Vendor\Psr\Http\Message\UriInterface;
7 use YoastSEO_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(\YoastSEO_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 \YoastSEO_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(\YoastSEO_Vendor\Symfony\Polyfill\Intl\Idn\Idn::class, 'idn_to_ascii')) {
78 return \YoastSEO_Vendor\Symfony\Polyfill\Intl\Idn\Idn::idn_to_ascii($domain, $options, \YoastSEO_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