0 follower

Final Class Yiisoft\Validator\Rule\StopOnErrorHandler

InheritanceYiisoft\Validator\Rule\StopOnErrorHandler
ImplementsYiisoft\Validator\RuleHandlerInterface

A handler for {@see StopOnError} rule. Validates a set of rules consecutively and stops at the rule where validation has failed.

Public Methods

Hide inherited methods

Method Description Defined By
validate() Yiisoft\Validator\Rule\StopOnErrorHandler

Method Details

Hide inherited methods

validate() public method

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 StopOnError) {
        throw new UnexpectedRuleException(StopOnError::class, $rule);
    }
    foreach ($rule->getRules() as $relatedRule) {
        $result = $context->validate($value, $relatedRule);
        if (!$result->isValid()) {
            return $result;
        }
    }
    return new Result();
}