src/Base/Model.php
public function validate($attributeNames = null, $clearErrors = true)
    {
        if ($clearErrors) {
            $this->clearErrors();
        }

        if (!$this->beforeValidate()) {
            return reject(new ValidationError("Before validate error"));
        }

        $scenarios = $this->scenarios();
        $scenario = $this->getScenario();
        if (!isset($scenarios[$scenario])) {
            throw new InvalidArgumentException("Unknown scenario: $scenario");
        }

        if ($attributeNames === null) {
            $attributeNames = $this->activeAttributes();
        }

        $attributeNames = (array)$attributeNames;

        $validationPromises = [];
        foreach ($this->getActiveValidators() as $validator) {
            $validationPromises[] = $validator->validateAttributes($this, $attributeNames);
        }
        return Reaction\Promise\allInOrder($validationPromises)
            ->always(function() {
                $this->afterValidate();
            })->then(function() {
                return !$this->hasErrors() ? true : reject(new ValidationError("Validation error"));
            });
    }
public function validate($attributeNames = null, $clearErrors = true)
    {
        if ($clearErrors) {
            $this->clearErrors();
        }

        if (!$this->beforeValidate()) {
            return reject(new ValidationError("Before validate error"));
        }

        $scenarios = $this->scenarios();
        $scenario = $this->getScenario();
        if (!isset($scenarios[$scenario])) {
            throw new InvalidArgumentException("Unknown scenario: $scenario");
        }

        if ($attributeNames === null) {
            $attributeNames = $this->activeAttributes();
        }

        $attributeNames = (array)$attributeNames;

        $validationPromises = [];
        foreach ($this->getActiveValidators() as $validator) {
            $validationPromises[] = $validator->validateAttributes($this, $attributeNames);
        }
        return Reaction\Promise\allInOrder($validationPromises)
            ->always(function() {
                $this->afterValidate();
            })->then(function() {
                return !$this->hasErrors() ? true : reject(new ValidationError("Validation error"));
            });
    }
Performs the data validation.

This method executes the validation rules applicable to the current [[scenario]].
The following criteria are used to determine whether a rule is currently applicable:

- the rule must be associated with the attributes relevant to the current scenario;
- the rules must be effective for the current scenario.

This method will call [[beforeValidate()]] and [[afterValidate()]] before and
after the actual validation, respectively. If [[beforeValidate()]] returns false,
the validation will be cancelled and [[afterValidate()]] will not be called.

Errors found during the validation can be retrieved via [[getErrors()]],
[[getFirstErrors()]] and [[getFirstError()]].

@param string[]|string $attributeNames attribute name or list of attribute names that should be validated.
If this parameter is empty, it means any attribute listed in the applicable
validation rules should be validated.
@param bool $clearErrors whether to call [[clearErrors()]] before performing validation
@return ExtendedPromiseInterface with bool whether the validation is successful without any error.
@throws InvalidArgumentException if the current scenario is unknown.