diff --git a/src/functions.php b/src/functions.php index cdb5ab2..6f80676 100644 --- a/src/functions.php +++ b/src/functions.php @@ -2,25 +2,27 @@ namespace LibDNS; -if (\function_exists('idn_to_ascii')) { - function normalize_name(string $label): string - { - if (false === $result = \idn_to_ascii($label, 0, INTL_IDNA_VARIANT_UTS46)) { - throw new \InvalidArgumentException("Label '{$label}' could not be processed for IDN"); - } +if (!\function_exists('LibDNS\\normalize_name')) { + if (\function_exists('idn_to_ascii')) { + function normalize_name(string $label): string + { + if (false === $result = \idn_to_ascii($label, 0, INTL_IDNA_VARIANT_UTS46)) { + throw new \InvalidArgumentException("Label '{$label}' could not be processed for IDN"); + } - return $result; - } -} else { - function normalize_name(string $label): string - { - if (\preg_match('/[\x80-\xff]/', $label)) { - throw new \InvalidArgumentException( - "Label '{$label}' contains non-ASCII characters and IDN support is not available." - . " Verify that ext/intl is installed for IDN support." - ); + return $result; } + } else { + function normalize_name(string $label): string + { + if (\preg_match('/[\x80-\xff]/', $label)) { + throw new \InvalidArgumentException( + "Label '{$label}' contains non-ASCII characters and IDN support is not available." + ." Verify that ext/intl is installed for IDN support." + ); + } - return \strtolower($label); + return \strtolower($label); + } } }