Creates this Verification model from the existing $model for the $attribute.
@param Model $model
@param $attribute
@return static
518555
public static function fromModel(Model $model, $attribute)
    {
        $valueAttribute = $attribute . '_confirmed';
        $levelAttribute = $attribute . '_confirm_level';
        $dateAttribute = $attribute . '_confirm_date';

        $modelValue = $model->$attribute;
        $value = isset($model->$valueAttribute) ? $model->$valueAttribute : null;
        $level = isset($model->$levelAttribute) ? $model->$levelAttribute : null;
        $date = isset($model->$dateAttribute) ? $model->$dateAttribute : null;

        $options = [
            'id' => $model->id,
            'type' => $attribute,
            'contact' => $model,
        ];

        if (isset($date)) {
            $options['date'] = $date;
        }

        // TODO: get rid of this crutch. Move into VerificationValueNormalizer or so
        if (in_array($attribute, ['voice_phone', 'fax_phone'], true) && !empty($value)) {
            $value = preg_replace('/[^0-9]/', '', $value);
            $modelValue = preg_replace('/[^0-9]/', '', $modelValue);
        }

        if (isset($level)) {
            $options['level'] = $level;
        } elseif (isset($value) && $value === $modelValue) {
            $options['level'] = static::LEVEL_CONFIRMED;
        } else {
            $options['level'] = static::LEVEL_UNCONFIRMED;
        }

        return new static($options);
    }
320378
protected static function isOwnedVia($attribute, Model $authority, Model $model)
    {
        if ($attribute instanceof Closure) {
            return $attribute($model, $authority);
        }

        return $authority->getKey() == $model->{$attribute};
    }
1027281
public function rangeField($model, $attribute, $htmlOptions = array())
    {
        return $this->createInput(TbHtml::INPUT_TYPE_RANGE, $model, $attribute, $htmlOptions);
    }
12038
public function validateAttribute($model, $attribute)
    {
        $country = '';
        if ($this->country !== null) {
            $country = $this->country;
        } elseif ($this->countryAttribute !== null) {
            $country = $model->{$this->countryAttribute};
        } elseif ($this->countryCodeAttribute !== null) {
            $country = $model->{$this->countryCodeAttribute};
        }
        // if empty country and used strict mode
        if (empty($country) && $this->strict) {
            $this->addError($model, $attribute, Yii::t('app', $this->strictModeMessage));

            return false;
        }
        if (empty($country)) {
            return true;
        }
        $phoneUtil = PhoneNumberUtil::getInstance();
        try {
            $numberProto = $phoneUtil->parse($model->$attribute, $country);
            if ($phoneUtil->isValidNumber($numberProto)) {
                if ($this->format) {
                    $model->$attribute = $phoneUtil->format($numberProto, PhoneNumberFormat::INTERNATIONAL);
                }

                return true;
            } else {
                $this->addError($model, $attribute, Yii::t('app', $this->message));

                return false;
            }
        } catch (NumberParseException $e) {
            $this->addError($model, $attribute, Yii::t('app', $this->numberParseExceptionMessage));
        }
    }
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);
    }
1320564
public function copyForUpdateTo( $model, $attributes = [] ) {

		foreach ( $attributes as $attribute ) {

			$model->setAttribute( $attribute, $this->getAttribute( $attribute ) );
		}
	}
560238
public function newModelInstance($attributes = [])
    {
        return $this->model->newInstance($attributes)->setConnection(
            $this->query->getConnection()
        );
    }
621846
public static function isOwnedBy(Model $authority, Model $model)
    {
        $type = get_class($model);

        if (isset(static::$ownership[$type])) {
            $attribute = static::$ownership[$type];
        } elseif (isset(static::$ownership['*'])) {
            $attribute = static::$ownership['*'];
        } else {
            $attribute = strtolower(static::basename($authority)).'_id';
        }

        return static::isOwnedVia($attribute, $authority, $model);
    }
349972
protected function makeModelExportColumnDataForAttributeData(ModelAttributeData $attribute)
    {
        return new ModelExportColumnData([
            'hide'     => false,
            'source'   => $attribute->name,
            'strategy' => $this->determineExportColumnStrategyForAttribute($attribute),
        ]);
    }
446666
protected function _create(array $attributes)
    {
        $model = $this->newModelInstance()->forceFill($attributes);

        $model->save();

        return $model;
    }
1241398
public function removeAttribute($attribute)
    {
        if (array_key_exists($attribute, $this->attributes)) {
            unset($this->attributes[$attribute]);
        }

        return $this;
    }
1106645
public function setAttribute($attribute, $value)
    {
        Arr::set($this->attributes, $attribute, $value);

        return $this;
    }
949180
private function updateAttribute($attribute, $value)
    {
        if (property_exists($this, $attribute)) {
            $this->$attribute = $value;
        }

        return $this;
    }
1330927
public static function activeUneditableField($model, $attribute, $htmlOptions = array())
    {
        parent::resolveNameID($model, $attribute, $htmlOptions);
        $value = parent::resolveValue($model, $attribute);
        TbArray::removeValues(array('name', 'id'), $htmlOptions);
        return self::uneditableField($value, $htmlOptions);
    }
659687
protected static function decryptAttributes(Model $model)
    {
        foreach (static::getEncryptedAttributes() as $attribute) {
            try {
                if (is_string($model->$attribute)) {
                    $model->$attribute = static::getEncrypter()->decrypt($model->$attribute);
                }
            } catch (DecryptException $e) {
            }
        }

        return $model;
    }
732136
public static function activeCheckboxSmart($model, $attribute, $options = [])
    {
        $name = isset($options['name']) ? $options['name'] : static::getInputName($model, $attribute);
        $value = static::getAttributeValue($model, $attribute);
        if (!array_key_exists('value', $options)) {
            $options['value'] = '1';
        }
        if (!array_key_exists('uncheck', $options)) {
            $options['uncheck'] = '0';
        }
        if (!array_key_exists('label', $options)) {
            $options['label'] = static::encode($model->getAttributeLabel(static::getAttributeName($attribute)));
        }
        $checked = "$value" === "{$options['value']}";
        if (!array_key_exists('id', $options)) {
            $options['id'] = static::getInputId($model, $attribute);
        }
        return static::checkboxSmart($name, $checked, $options);
    }
540209
public function addAttribute(Attribute$attribute) : Attributes
	{
		$this->getItems();//max sure is array
		$this->attributes[$attribute->getName()] = $attribute;
		return $this;
	}