Validates the attribute of the object.
If there is any error, the error message is added to the object.
@param CModel $object the object being validated
@param string $attribute the attribute being validated
430854
protected function validateAttribute($object,$attribute)
	{
		$value=$object->$attribute;
		if($this->allowEmpty && $this->isEmpty($value))
			return;
		$captcha=$this->getCaptchaAction();
		// reason of array checking is explained here: https://github.com/yiisoft/yii/issues/1955
		if(is_array($value) || !$captcha->validate($value,$this->caseSensitive))
		{
			$message=$this->message!==null?$this->message:Yii::t('yii','The verification code is incorrect.');
			$this->addError($object,$attribute,$message);
		}
	}
1125217
public function validatePassword($attribute)
    {
        if (!$this->hasErrors()) {
            if ($this->user === null || !PasswordHelper::validate($this->password, $this->user->password_hash)) {
                $this->addError($attribute, Yii::t('yuncms', 'Invalid login or password'));
            }
        }
    }
926664
public function validateTwig($attribute)
    {
        $twig = $this->getTwig(new \Twig_Loader_String());

        try {
            $twig->render($this->$attribute);
        } catch (\Exception $e) {
            $message = "Error compiling {$attribute}: " . $e->getMessage();
            $this->addError($attribute, $message);
        }
    }
388667
public function validateUser( $attribute, $params ) {

        if( !$this->hasErrors() ) {

			$user = $this->user;

            if( !isset( $user ) ) {

				$this->addError( $attribute, Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_USER_NOT_EXIST ) );
            }
			else {

				if( !$this->hasErrors() && !$user->isVerified( false ) ) {

					$this->addError( $attribute, Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_USER_VERIFICATION ) );
				}

				if( !$this->hasErrors() && $user->isBlocked() ) {

					$this->addError( $attribute, Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_BLOCKED ) );
				}
			}
        }
    }
1079454
protected function validateAttribute($object,$attribute)
	{
		if(!$this->setOnEmpty)
			$object->$attribute=$this->value;
		else
		{
			$value=$object->$attribute;
			if($value===null || $value==='')
				$object->$attribute=$this->value;
		}
	}
365937
protected function validate($object)
    {
        $errorList = $this->get('validator')->validate($object);
        if (0 < $errorList->count()) {
            $message = 'Row validation failed.';
            if ($this->getParameter('kernel.debug')) {
                $messages = [];
                /** @var \Symfony\Component\Validator\ConstraintViolationInterface $error */
                foreach ($errorList as $error) {
                    $messages[] = $error->getMessage();
                }
                $message = implode(', ', $messages);
            }
            throw new BadRequestHttpException($message);
        }
    }
300284
protected function validateAttribute($object, $attribute)
    {
        $value = $object->{$attribute};
        if ($this->isEmpty($value)) {
            $this->validateEmpty($object, $attribute);
            return;
        }
        if (
            (!$this->strict && $value != $this->trueValue && $value != $this->falseValue)
            || ($this->strict && $value !== $this->trueValue && $value !== $this->falseValue)
        ) {
            $this->addError($object, $attribute, $this->message, [
                '{true}' => $this->trueValue,
                '{false}' => $this->falseValue,
            ]);
        }
    }
963935
public function validateMobileCreate( $attribute, $params ) {

		if( !$this->hasErrors() ) {

			if( self::isExistByMobile( $this->mobile ) ) {

				$this->addError( $attribute, Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_MOBILE_EXIST ) );
			}
		}
	}
114438
public function validate(Validation $validation, $attribute)
    {
        $value = $validation->getValue($attribute);
        $modelName = $this->getOption('model', null);
        $conditions = $this->getOption('conditions', null);
        $bind = $this->getOption('bind', []);
        $showMessages = $this->getOption('show_messages', true);
        $compareColumn = $this->getOption('compare_column', null);
        $compareWithSensitivity = $this->getOption('compare_with_sensitivity', true);

        /** @var \Phalcon\Mvc\Model $model */
        $model = $this->getModel($modelName);

        if (is_null($conditions)) {
            if (is_null($value)) {
                return false;
            }
            $data = $model::findFirst(["id = ?0", "bind" => $value]);
        } else {
            $data = $model::findFirst(['conditions' => $conditions, 'bind' => $bind]);
        }
        if (!$data) {
            if ($showMessages) {
                $this->addMessageToValidation($validation, 'Invalid :field supplied', $attribute, 'Model');
            }
            return false;
        }

        if ($compareColumn) {
            $value = ($compareWithSensitivity) ? $value : strtolower($value);
            $modelValue = ($compareWithSensitivity) ? $data->{$compareColumn} : strtolower($data->{$compareColumn});
            if ($modelValue != $value) {
                return false;
            }
        }

        return true;
    }
995817
public function validatePassword($attribute, $params)
    {
      if ($this->user === null || !Password::validate($this->password, $this->user->password_hash))
        $this->addError($attribute, Yii::t('user', 'Invalid login or password'));
    }
1256780
protected function validateTagAttribute(string $attribute) : bool
    {
        if (!empty($this->attributePattern)) {
            $matches = [];
            return preg_match($this->attributePattern, $attribute, $matches);
        } else {
            return empty($attribute);
        }
    }
121874
protected function addError($attribute, $message)
    {
        if (!isset($this->errors[$attribute])) {
            $this->errors[$attribute] = array();
        }
        $this->errors[$attribute][] = $message;
    }
1193073
protected function parse($object)
    {
        if (! is_object($object)) {
            throw new ValidationException('Attributes has to be an object, "' . gettype($object) . '" given.');
        }

        if (property_exists($object, 'type') or property_exists($object, 'id') or property_exists($object, 'relationships') or property_exists($object, 'links')) {
            throw new ValidationException('These properties are not allowed in attributes: `type`, `id`, `relationships`, `links`');
        }

        $object_vars = get_object_vars($object);

        if (count($object_vars) === 0) {
            return $this;
        }

        foreach ($object_vars as $name => $value) {
            $this->set($name, $value);
        }
    }
760144
protected function validate($object): void
    {
        $needType = $this->type();

        if (!$object instanceof $needType) {
            throw new \InvalidArgumentException("Element " . get_class($object) . " must be instance of " . $needType);
        }
    }
372150
protected function checkAttribute(/*# string */ $attribute)
    {
        if (!defined($attribute)) {
            throw new LogicException(
                Message::get(Message::DB_ATTRIBUTE_UNKNOWN, $attribute),
                Message::DB_ATTRIBUTE_UNKNOWN
            );
        }
    }
1216922
protected function addError($object, $attribute, $message, $params = [])
    {
        $params['{attribute}'] = $object->getAttributeLabel($attribute);
        $object->addError($attribute, str_cover($message, $params));
    }
487734
public function validateEmailUpdate( $attribute, $params ) {

		if( !$this->hasErrors() ) {

			$existingUser = self::findByEmail( $this->email );

			if( isset( $existingUser ) && $this->id != $existingUser->id ) {

				$this->addError( $attribute, Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_EMAIL_EXIST ) );
			}
		}
	}