Beispiel #1
0
 public function testIP()
 {
     $inputs = array(array('ip' => "192.168.0.1", 'flags' => null, 'res' => true), array('ip' => "192.168.1.1", 'flags' => FILTER_FLAG_IPV4, 'res' => true), array('ip' => "192.168.2.1", 'flags' => FILTER_FLAG_IPV6, 'res' => false), array('ip' => "::1", 'flags' => null, 'res' => true), array('ip' => "dead:beaf::1", 'flags' => FILTER_FLAG_IPV4, 'res' => false), array('ip' => "dead:beaf::2", 'flags' => FILTER_FLAG_IPV6, 'res' => true));
     foreach ($inputs as $i) {
         $ip = $i['ip'];
         $flags = $i['flags'];
         $res = $i['res'];
         try {
             $w = validator\Net::ipAddress($ip, $flags);
         } catch (Invalid $e) {
             if (!$res) {
                 continue;
             }
             $this->fail(sprintf('This value should be good: %s.', $ip));
         }
         if (!$res) {
             $this->fail(sprintf('This value should be bad: %s.', $ip));
         }
     }
 }
Beispiel #2
0
 public function __construct($params = array())
 {
     parent::__construct($params);
     $this->validators[] = function ($value) {
         return validator\Net::ipAddress($value, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6);
     };
 }