Final Class Yiisoft\Validator\Rule\InHandler
| Inheritance | Yiisoft\Validator\Rule\InHandler |
|---|---|
| Implements | Yiisoft\Validator\RuleHandlerInterface |
Validates that the value is one of the values provided.
See also Yiisoft\Validator\Rule\In.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| validate() | Yiisoft\Validator\Rule\InHandler |
Method Details
| public Yiisoft\Validator\Result validate ( mixed $value, Yiisoft\Validator\RuleInterface $rule, Yiisoft\Validator\ValidationContext $context ) | ||
| $value | mixed | |
| $rule | Yiisoft\Validator\RuleInterface | |
| $context | Yiisoft\Validator\ValidationContext | |
public function validate(mixed $value, RuleInterface $rule, ValidationContext $context): Result
{
if (!$rule instanceof In) {
throw new UnexpectedRuleException(In::class, $rule);
}
$result = new Result();
if ($rule->isNot() === ArrayHelper::isIn($value, $rule->getValues(), $rule->isStrict())) {
$result->addError(
$rule->getMessage(),
[
'property' => $context->getTranslatedProperty(),
'Property' => $context->getCapitalizedTranslatedProperty(),
],
);
}
return $result;
}
Signup or Login in order to comment.