Exemple #1
0
 /**
  * @dataProvider iPvFutureAddressesProvider
  */
 public function testIPvFutureAddresses($ip, $expected)
 {
     $this->options['allowipvfuture'] = true;
     $this->options['allowliteral'] = true;
     $this->validator->setOptions($this->options);
     $this->assertEquals($expected, $this->validator->isValid($ip));
 }
Exemple #2
0
 /**
  * Check if a host name is a valid IP address, depending on allowed IP address types
  *
  * @param  string  $host
  * @param  integer $allowed allowed address types
  * @return boolean
  */
 protected static function isValidIpAddress($host, $allowed)
 {
     $validatorParams = array('allowipv4' => (bool) ($allowed & self::HOST_IPV4), 'allowipv6' => false, 'allowipvfuture' => false, 'allowliteral' => false);
     // Test only IPv4
     $validator = new Validator\Ip($validatorParams);
     $return = $validator->isValid($host);
     if ($return) {
         return true;
     }
     // IPv6 & IPvLiteral must be in literal format
     $validatorParams = array('allowipv4' => false, 'allowipv6' => (bool) ($allowed & self::HOST_IPV6), 'allowipvfuture' => (bool) ($allowed & self::HOST_IPVFUTURE), 'allowliteral' => true);
     static $regex = '/^\\[.*\\]$/';
     $validator->setOptions($validatorParams);
     return preg_match($regex, $host) && $validator->isValid($host);
 }