0 follower

Interface Yiisoft\Validator\ValidatorInterface

Implemented byYiisoft\Validator\Debug\ValidatorInterfaceProxy, Yiisoft\Validator\Validator

An interface allowing to validate the data according to the set of rules ({@see RuleInterface}) and validation context ({@see ValidationContext}). A class implementing it is called "validator".

Public Methods

Hide inherited methods

Method Description Defined By
validate() Validates the data according to the set of rules ({@see RuleInterface}) and validation context ({@see ValidationContext}). Yiisoft\Validator\ValidatorInterface

Method Details

Hide inherited methods

validate() public abstract method

Validates the data according to the set of rules ({@see RuleInterface}) and validation context ({@see ValidationContext}).

public abstract Yiisoft\Validator\Result validate ( Yiisoft\Validator\DataSetInterface|mixed|Yiisoft\Validator\RulesProviderInterface $data, callable|iterable|object|string|null $rules null, Yiisoft\Validator\ValidationContext|null $context null )
$data Yiisoft\Validator\DataSetInterface|mixed|Yiisoft\Validator\RulesProviderInterface

Data to validate:

  • A data set ({@see \Yiisoft\Validator\DataSetInterface}) is used as is.
  • Implementing {@see \Yiisoft\Validator\RulesProviderInterface} additionally can be used for providing rules via {@see \Yiisoft\Validator\RulesProviderInterface::getRules()} (works only when $rules argument is not provided and ignored otherwise).
  • Any other value is normalized to data set using {@see \Yiisoft\Validator\Helper\DataSetNormalizer}.
$rules callable|iterable|object|string|null

Rules to apply for validating data. If specified, this argument has higher priority over {@see \Yiisoft\Validator\RulesProviderInterface::getRules()} provided in $data argument. A variety of types is supported. They are normalized before usage, please refer to {@see \Yiisoft\Validator\Helper\RulesNormalizer} documentation to see what structures can be passed.

$context Yiisoft\Validator\ValidationContext|null

Validation context that may be taken into account when performing validation.

return Yiisoft\Validator\Result

The result of validation.

throws ReflectionException

If an object / {@see \Yiisoft\Validator\ObjectDataSet} providing rules or (and) data used in $data argument and there was a {@see \Reflection} error during parsing them.

                public function validate(
    mixed $data,
    callable|iterable|object|string|null $rules = null,
    ?ValidationContext $context = null,
): Result;