Pop\Validator\Subnet::evaluate PHP Method

evaluate() public method

Method to evaluate the validator
public evaluate ( mixed $input = null ) : boolean
$input mixed
return boolean
    public function evaluate($input = null)
    {
        // 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 a valid IPv4 subnet.');
            } else {
                $this->defaultMessage = I18n::factory()->__('The value must not be a valid IPv4 subnet.');
            }
        }
        // Evaluate the input against the validator
        if (preg_match('/^\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]|[0-9])\\b$/', $this->input) == $this->condition) {
            $this->result = true;
        } else {
            $this->result = false;
        }
        return $this->result;
    }

Usage Example

Example #1
0
 public function testEvaluateFalse()
 {
     $v = new Subnet(null, null, false);
     $this->assertFalse($v->evaluate('192.168.1'));
     $this->assertTrue($v->evaluate('123456'));
 }
Subnet