Final Class Yiisoft\Validator\Rule\AnyRuleHandler
| Inheritance | Yiisoft\Validator\Rule\AnyRuleHandler |
|---|---|
| Implements | Yiisoft\Validator\RuleHandlerInterface |
A handler for {@see AnyRule} rule. Validates a set of rules consecutively and stops at the rule where validation has passed.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| validate() | Yiisoft\Validator\Rule\AnyRuleHandler |
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 AnyRule) {
throw new UnexpectedRuleException(AnyRule::class, $rule);
}
foreach ($rule->getRules() as $relatedRule) {
$result = $context->validate($value, $relatedRule);
if ($result->isValid()) {
return $result;
}
}
return (new Result())->addError($rule->getMessage(), []);
}
Signup or Login in order to comment.