各类型上传文件验证
@param $attribute
@param $params
552399
public function checkFile($attribute, $params)
    {
        // 按照类型 验证上传
        switch ($this->type) {
            case Media::TYPE_IMAGE:
                $rule = [[$attribute], 'file', 'skipOnEmpty' => false, 'extensions' => 'jpg', 'maxSize' => 1048576]; // 1MB
                break;
            case Media::TYPE_THUMB:
                $rule = [[$attribute], 'file', 'skipOnEmpty' => false, 'extensions' => 'jpg', 'maxSize' => 524288]; // 64KB
                break;
            case Media::TYPE_VOICE:
                $rule = [[$attribute], 'file', 'skipOnEmpty' => false, 'extensions' => 'amr, mp3', 'maxSize' => 2097152]; // 2MB
                break;
            case Media::TYPE_VIDEO:
                $rule = [[$attribute], 'file', 'skipOnEmpty' => false, 'extensions' => 'mp4', 'maxSize' => 10485760]; // 10MB
                break;
            default:
                return ;
        }
        $validator = Validator::createValidator($rule[1], $this, (array) $rule[0], array_slice($rule, 2));
        $validator->validateAttributes($this);
    }
1112260
public function validateUsernameUpdate( $attribute, $params ) {

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

			$existingUser = self::findByUsername( $this->username );

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

				$this->addError( $attribute, Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_USERNAME_EXIST ) );
			}
		}
	}
1217316
public function validateReservedWord($attribute,$params)
	{
		$value=$this->$attribute;
		if(in_array(strtolower($value),self::$keywords))
			$this->addError($attribute, $this->getAttributeLabel($attribute).' cannot take a reserved PHP keyword.');
	}
1201616
public function already_selected($attribute, $params)
    {
        if($this->$attribute && $this->find()->where($attribute . '=' . $this->$attribute . 
            ($this->id ? ' and id <> ' . $this->id : '')
        )->one())
            $this->addError($attribute, $params['message']);
    }
1235429
public function validateEmail( $attribute, $params ) {

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

			if( $this->userService->isExistByEmail( $this->email ) ) {

				$this->addError( $attribute, Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_EMAIL_EXIST ) );
			}
		}
	}
1311910
public function action($action, $content, array $parameters = [], array $attributes = [])
    {
        $action = [$action, $parameters];

        $this->makeSubItem('action', compact('action', 'content', 'attributes'));
    }
177345
public function gmdate($attribute, $params, $validator)
    {
        if (isset($this->$attribute)) {
            $timestamp = strtotime($this->$attribute);
            $this->{$attribute . 'InUtc'} = gmdate('Y-m-d H:i:s', $timestamp);
        }
    }
1365203
public function validateAttribute($model, $attribute)
    {
        $this->_model = $model;
        $this->_attributeName = $attribute;
        $result = $this->validateValue($model->$attribute);
        if (!empty($result)) {
            $this->addError($model, $attribute, $result[0], $result[1]);
        }
    }
684965
protected function renderAttr($attributes = false, $params = false)
    {
        $attrStr = '';

        if (isset($attributes['callback'])) {
            $callbackParams = [$this];

            if ($params !== false) {
                array_push($callbackParams, $params);
            }

            call_user_func_array($attributes['callback'], $callbackParams);
        }

        if (is_array($attributes)) {
            foreach ($attributes as $attr => $value) {
                if (is_string($value)) {
                    $attrStr .= ' '.$attr.'="'.$value.'"';
                }
            }
        }

        return $attrStr;
    }
1098990
private function checkAttrExists($attribute)
    {
        foreach ($this->attributes as $attr => $options) {
            $this->ensureAttributes($attr, $options);
            if ($attr == $attribute) {
                return;
            }
        }
        throw new InvalidParamException();
    }
1035938
public static function updateAllAsync($attributes, $condition = '', $params = [])
    {
        Yii::$app->queue->push(new UpdateActiveRecordAllJob([
            'modelClass' => get_called_class(),
            'condition' => $condition,
            'attributes' => $attributes,
            'params' => $params
        ]));
    }
782043
protected function validateMimetypes( $attribute, $value, $parameters )
	{
		if ( !$this->isAValidFileInstance( $value ) )
		{
			return false;
		}

		return $value->getPath() != '' && in_array( $value->getMimeType(), $parameters );
	}
1216922
protected function addError($object, $attribute, $message, $params = [])
    {
        $params['{attribute}'] = $object->getAttributeLabel($attribute);
        $object->addError($attribute, str_cover($message, $params));
    }
690952
public function validatePassword($attribute, $params)
    {
        if (!$this->hasErrors()) {
            $user = $this->getUser();
            if (!$user || !$user->validatePassword($this->password)) {
                $this->addError($attribute, Yii::t($this->tcModule, 'Incorrect username or password.'));
            }
        }
    }
780802
public function validateUsernameChange( $attribute, $params ) {

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

			$properties		= CoreProperties::getInstance();
			$existingUser	= self::findById( $this->id );

			if( isset( $existingUser ) && $existingUser->username !== $this->username  && !$properties->isChangeUsername() ) {

				$this->addError( $attribute, Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_CHANGE_USERNAME ) );
			}
		}
	}
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 ) );
			}
		}
	}
636056
public function validateRelation($attribute, $params)
    {
        $relation = $this->getRelation($attribute);
        $attributes = isset($params['attributes']) ? $params['attributes'] : null;
        $errors = [];

        $models = $this->$attribute;
        if (!$relation->multiple) {
            $models = [$models];
        }
        /** @var \yii\db\ActiveRecord[] $models */
        foreach ($models as $index => $model) {
            if (isset($params['scenario'])) {
                $model->scenario = $params['scenario'];
            }

            if ($model->validate($attributes)) {
                continue;
            }
            $errors[] = (string)$model . ': ' . \yii\helpers\Html::errorSummary($model, ['header' => '']) ;
        }

        $this->populateRelation($attribute, $relation->multiple ? $models : $models[0]);
        if (empty($errors)) {
            return;
        }

        $errors = "<ul><li>" . implode("</li>\n<li>", $errors) . "</li></ul>";

        $placeholders = [
            'attribute' => $this->getRelationLabel($relation, $attribute),
        ];
        $message = $relation->multiple
            ? \Yii::t('app', '{attribute} have invalid items:', $placeholders)
            : \Yii::t('app', '{attribute} is invalid:', $placeholders);
        $this->addError($attribute, $message . $errors);
    }