Final Class Yiisoft\Validator\Rule\SubsetHandler
| Inheritance | Yiisoft\Validator\Rule\SubsetHandler |
|---|---|
| Implements | Yiisoft\Validator\RuleHandlerInterface |
A handler for {@see Subset} rule. Validates that the set of values is a subset of another set.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| validate() | Yiisoft\Validator\Rule\SubsetHandler |
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 Subset) {
throw new UnexpectedRuleException(Subset::class, $rule);
}
if (!is_iterable($value)) {
return (new Result())->addError($rule->getIncorrectInputMessage(), [
'property' => $context->getTranslatedProperty(),
'Property' => $context->getCapitalizedTranslatedProperty(),
'type' => get_debug_type($value),
]);
}
if (!ArrayHelper::isSubset($value, $rule->getValues(), $rule->isStrict())) {
return (new Result())->addError($rule->getMessage(), [
'property' => $context->getTranslatedProperty(),
'Property' => $context->getCapitalizedTranslatedProperty(),
]);
}
return new Result();
}
Signup or Login in order to comment.