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