20 return function_exists(
'hrtime') ? hrtime(
true) / 1e9 : microtime(
true);
34 $asciiHost = self::idnToAsci($uri->
getHost(), $options, $info);
35 if ($asciiHost ===
false) {
36 $errorBitSet = isset($info[
'errors']) ? $info[
'errors'] : 0;
38 $errorConstants = array_filter(array_keys(get_defined_constants()),
function ($name) {
39 return substr($name, 0, 11) ===
'IDNA_ERROR_';
43 foreach ($errorConstants as $errorConstant) {
44 if ($errorBitSet & constant($errorConstant)) {
45 $errors[] = $errorConstant;
49 $errorMessage =
'IDN conversion failed';
51 $errorMessage .=
' (errors: ' . implode(
', ', $errors) .
')';
56 if ($uri->
getHost() !== $asciiHost) {
73 private static function idnToAsci($domain, $options, &$info = [])
75 if (\preg_match(
'%^[ -~]+$%', $domain) === 1) {
79 if (\extension_loaded(
'intl') && defined(
'INTL_IDNA_VARIANT_UTS46')) {
80 return \idn_to_ascii($domain, $options, INTL_IDNA_VARIANT_UTS46, $info);
87 return Idn::idn_to_ascii($domain, $options, Idn::INTL_IDNA_VARIANT_UTS46, $info);