35        $length = strlen($string);
 
   45        if ($length > 1 && $string[0] === 
'[' && $string[$length - 1] === 
']') {
 
   47            $ip = substr($string, 1, $length - 2);
 
   57        if (
$ipv4 !== 
false) {
 
   77        $underscore = 
$config->get(
'Core.AllowHostnameUnderscore') ? 
'_' : 
'';
 
   84        $and = 
"[a-z0-9-$underscore]"; 
 
   86        $domainlabel = 
"$an(?:$and*$an)?";
 
   90        $toplabel = 
"$an(?:$and*$an)?";
 
   92        if (preg_match(
"/^(?:$domainlabel\.)*($toplabel)\.?$/i", $string, $matches)) {
 
   93            if (!ctype_digit($matches[1])) {
 
   99        if (function_exists(
'idn_to_ascii')) {
 
  100            if (defined(
'IDNA_NONTRANSITIONAL_TO_ASCII') && defined(
'INTL_IDNA_VARIANT_UTS46')) {
 
  101                $string = idn_to_ascii($string, IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46);
 
  103                $string = idn_to_ascii($string);
 
  109        } elseif (
$config->get(
'Core.EnableIDNA')) {
 
  110            $idna = 
new Net_IDNA2(array(
'encoding' => 
'utf8', 
'overlong' => 
false, 
'strict' => 
true));
 
  112            $parts = explode(
'.', $string);
 
  114                $new_parts = array();
 
  115                foreach ($parts as $part) {
 
  117                    for (
$i = 0, 
$c = strlen($part); 
$i < 
$c; 
$i++) {
 
  118                        if (ord($part[
$i]) > 0x7a) {
 
  124                        $new_parts[] = $part;
 
  126                        $new_parts[] = $idna->encode($part);
 
  129                $string = implode(
'.', $new_parts);
 
  130            } 
catch (Exception $e) {
 
  135        if (preg_match(
"/^($domainlabel\.)*$toplabel\.?$/i", $string)) {
 
An exception for terminatinating execution or to throw for unit testing.
Validates a host according to the IPv4, IPv6 and DNS (future) specifications.
validate($string, $config, $context)
Validates an IPv4 address.
Validates an IPv6 address.
Base class for all validating attribute definitions.