Pop\Validator\Length::evaluate PHP Метод

evaluate() публичный Метод

Method to evaluate the validator
public evaluate ( mixed $input = null ) : boolean
$input mixed
Результат 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 length must be equal to %1.', $this->value);
            } else {
                $this->defaultMessage = I18n::factory()->__('The value length must not be equal to %1.', $this->value);
            }
        }
        // Evaluate the input against the validator
        if ((strlen($this->input) == $this->value) == $this->condition) {
            $this->result = true;
        } else {
            $this->result = false;
        }
        return $this->result;
    }

Usage Example

Пример #1
0
 public function testEvaluateFalse()
 {
     $v = new Length(6, null, false);
     $this->assertFalse($v->evaluate('abcdef'));
     $this->assertTrue($v->evaluate('123'));
 }
Length