Final Class Yiisoft\Validator\Rule\InEnumHandler
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
Validates that the value is one of the values of a specified enum.
See also Yiisoft\
Public Methods
| Method | Description | Defined By |
|---|---|---|
| validate() | Yiisoft\ |
Method Details
| public Yiisoft\ | ||
| $value | mixed | |
| $rule | object | |
| $context | Yiisoft\ |
|
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;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.