Consider attribute value successfully validated if it is an instance of the given targetClass and this
instance was just created
@param Model $model
@param string $attribute
481044
public function validateAttribute($model, $attribute)
    {
        if (
            $this->targetClass !== null
            && $model->$attribute instanceof $this->targetClass
            && !empty($model->$attribute->isNewRecord)
        ) {
            return;
        }

        if ($model->isRelationPopulated($attribute)) {
            return;
        }

        parent::validateAttribute($model, $attribute);
    }
904783
protected function validateAttribute($object, $attribute)
    {
        $value = $object->{$attribute};
        if ($this->isEmpty($value)) {
            $this->addError($object, $attribute, $this->message);
        }
    }
1018228
protected function takeAttributeFromDOM($attribute)
    {
        switch ($attribute->localName) {
        case 'errorCode':
            $this->_errorCode = $attribute->nodeValue;
            break;
        case 'reason':
            $this->_reason = $attribute->nodeValue;
            break;
        case 'invalidInput':
            $this->_invalidInput = $attribute->nodeValue;
            break;
        default:
            parent::takeAttributeFromDOM($attribute);
        }
    }
1152096
public function attributeValidationException(AbstractAttribute $attribute, ValidationException $e)
    {
        $attrException = new AttributeValidationException($e->getMessage());
        $attrException->addError($attribute->getName(), $e->getMessage());

        return $attrException;
    }
950047
public function validateUrl ($attribute)
		{
			if (!$this->hasErrors())
			{
				if (filter_var($this->$attribute, FILTER_VALIDATE_URL) === false)
					$this->addError($attribute, Yii::tr('{attribute} is not a valid URL.', [ 'attribute' => $this->name ], 'setting'));
			}
		}
1136678
protected function setForeignAttributesForCreate(Model $model)
    {
        $foreignKey = $this->getForeignKeyName();
        $parentKeyValue = $this->getParentKey();
        if (is_array($foreignKey)) { //Check for multi-columns relationship
            foreach ($foreignKey as $index => $key) {
                $model->setAttribute($key, $parentKeyValue[$index]);
            }
        } else {
            parent::setForeignAttributesForCreate($model);
        }
    }
1320564
public function copyForUpdateTo( $model, $attributes = [] ) {

		foreach ( $attributes as $attribute ) {

			$model->setAttribute( $attribute, $this->getAttribute( $attribute ) );
		}
	}
410680
protected function isTranslatedTargetAttribute($target, Model $model)
    {
        // Normalize target as an array
        if (is_string($target)) {
            $target = explode('.', $target);
        }

        if ( ! is_array($target)) {
            throw new UnexpectedValueException("Target attribute/column should be a dot-notation string or array");
        }

        $current = array_shift($target);

        // If it is a direct attribute of the model, check whether it is translated
        if ( ! count($target)) {
            return (method_exists($model, 'isTranslationAttribute') && $model->isTranslationAttribute($current));
        }

        // Find the relations and the attribute, resolving relation methods where possible
        if (method_exists($model, $current)) {

            try {
                $relation = $model->{$current}();
            } catch (\Exception $e) {
                $relation = false;
            }

            if ( ! $relation || ! ($relation instanceof Relation)) {
                return false;
            }

            // Recursively check nested relation
            return $this->isTranslatedTargetAttribute($target, $relation->getRelated());
        }

        return false;
    }
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,
            ]);
        }
    }
1142217
public function validate(Validation $validation, $attribute)
    {
        $this->setOption('show_messages', false);
        $is_valid = !parent::validate($validation, $attribute);
        if (!$is_valid) {
            $this->addMessageToValidation($validation, ':field already exists', $attribute, 'NotExisting');
        }
        return $is_valid;
    }
966085
protected function validateAttribute($object,$attribute)
	{
		$value=$object->$attribute;
		if($this->allowEmpty && $this->isEmpty($value))
			return;
		if($this->compareValue!==null)
			$compareTo=$compareValue=$this->compareValue;
		else
		{
			$compareAttribute=$this->compareAttribute===null ? $attribute.'_repeat' : $this->compareAttribute;
			$compareValue=$object->$compareAttribute;
			$compareTo=$object->getAttributeLabel($compareAttribute);
		}

		switch($this->operator)
		{
			case '=':
			case '==':
				if(($this->strict && $value!==$compareValue) || (!$this->strict && $value!=$compareValue))
					$message=$this->message!==null?$this->message:Yii::t('yii','{attribute} must be repeated exactly.');
				break;
			case '!=':
				if(($this->strict && $value===$compareValue) || (!$this->strict && $value==$compareValue))
					$message=$this->message!==null?$this->message:Yii::t('yii','{attribute} must not be equal to "{compareValue}".');
				break;
			case '>':
				if($value<=$compareValue)
					$message=$this->message!==null?$this->message:Yii::t('yii','{attribute} must be greater than "{compareValue}".');
				break;
			case '>=':
				if($value<$compareValue)
					$message=$this->message!==null?$this->message:Yii::t('yii','{attribute} must be greater than or equal to "{compareValue}".');
				break;
			case '<':
				if($value>=$compareValue)
					$message=$this->message!==null?$this->message:Yii::t('yii','{attribute} must be less than "{compareValue}".');
				break;
			case '<=':
				if($value>$compareValue)
					$message=$this->message!==null?$this->message:Yii::t('yii','{attribute} must be less than or equal to "{compareValue}".');
				break;
			default:
				throw new CException(Yii::t('yii','Invalid operator "{operator}".',array('{operator}'=>$this->operator)));
		}
		if(!empty($message))
			$this->addError($object,$attribute,$message,array('{compareAttribute}'=>$compareTo,'{compareValue}'=>$compareValue));
	}
1353987
protected function replaceExistingModel($model, $attribute)
    {
        $modelAttributes = $model->attributes;
        unset($modelAttributes[$model->primaryKey()[0]]);

        foreach ($this->relationalData[$attribute]['oldModels'] as $oldModel) {
            /** @var ActiveRecord $oldModel */
            $oldModelAttributes = $oldModel->attributes;
            unset($oldModelAttributes[$oldModel->primaryKey()[0]]);

            if ($oldModelAttributes == $modelAttributes) {
                return $oldModel;
            }
        }

        return $model;
    }
952056
public static function ownedVia($model, $attribute = null)
    {
        if (is_null($attribute)) {
            static::$ownership['*'] = $model;
        }

        static::$ownership[$model] = $attribute;
    }
72750
protected function checkAttribute(AttributeInterface $attribute)
    {
        if (!$this->getFamily()->hasAttribute($attribute->getCode())) {
            throw new MissingAttributeException(
                "Attribute {$attribute->getCode()} doesn't exists in family {$this->getFamilyCode()}"
            );
        }
        if ($attribute->getFamily() !== $this->getFamily()) {
            $m = "Attribute {$attribute->getCode()} (from family '{$attribute->getFamily()->getCode()}') doesn't ";
            $m .= "belong to this family ('{$this->getFamilyCode()}')";
            throw new MissingAttributeException($m);
        }
    }
613290
protected void checkAttribute(String attribute) {
        if (!hasAttribute(attribute)) {
            String sb = "Attribute: '" + attribute + "' is not defined in model: '" + getModelClass() + ". "
                    + "Available attributes: " +getAttributeNames();
            throw new IllegalArgumentException(sb);
        }
    }
41450
public function validateModelId($attribute, $params)
    {
        /** @var ActiveRecord $class */
        $class = Model::findIdentity($this->model_class);
        if ($class === null) {
            $this->addError($attribute, \Yii::t('net_frenzel_communication', 'ERROR_MSG_INVALID_MODEL_ID'));
        } else {
            $model = $class->name;
            if ($model::find()->where(['id' => $this->entity_id]) === false) {
                $this->addError($attribute, \Yii::t('net_frenzel_communication', 'ERROR_MSG_INVALID_MODEL_ID'));
            }
        }
    }
891082
protected function validateUsingCustomRule($attribute, $value, $rule)
    {
        if (! $rule->passes($attribute, $value)) {
            $this->failedRules[$attribute][get_class($rule)] = [];

            $messages = (array) $rule->message();

            foreach ($messages as $message) {
                $this->messages->add($attribute, $this->makeReplacements(
                    $message, $attribute, get_class($rule), []
                ));
            }
        }
    }