Author: Nick Sagona, III (nick@popphp.org)
Inheritance: extends Validator
Exemplo n.º 1
0
 /**
  * Method to evaluate the validator
  *
  * @param  mixed $input
  * @throws Exception
  * @return boolean
  */
 public function evaluate($input = null)
 {
     // Check to make sure the input is a valid Ipv4 address.
     $ip = new Ipv4();
     if (!Ipv4::factory()->evaluate($input)) {
         throw new Exception('The IP address must be a valid IPv4 address.');
     }
     // Set the input, if passed
     if (null !== $input) {
         $this->input = $input;
     }
     // Set the default message
     if (null === $this->defaultMessage) {
         if ($this->condition) {
             $this->defaultMessage = I18n::factory()->__('The value must be part of the subnet %1.', $this->value);
         } else {
             $this->defaultMessage = I18n::factory()->__('The value must not be part of the subnet %1.', $this->value);
         }
     }
     // Evaluate the input against the validator
     if ((substr($this->input, 0, strrpos($this->input, '.')) == $this->value) == $this->condition) {
         $this->result = true;
     } else {
         $this->result = false;
     }
     return $this->result;
 }
Exemplo n.º 2
0
 /**
  * Method to filter the ip addresses to confirm their validity
  *
  * @param  string|array $ips
  * @return array
  */
 protected function filterIps($ips)
 {
     $validIps = array();
     if (!is_array($ips)) {
         $ips = array($ips);
     }
     foreach ($ips as $ip) {
         $ip = trim($ip);
         if (Validator\Ipv4::factory()->evaluate($ip) || Validator\Ipv6::factory()->evaluate($ip)) {
             $validIps[] = $ip;
         }
     }
     return $validIps;
 }
Exemplo n.º 3
0
 public function testEvaluateFalse()
 {
     $v = new Ipv4(null, null, false);
     $this->assertFalse($v->evaluate('192.168.1.10'));
     $this->assertTrue($v->evaluate('123456'));
 }