diff --git a/framework/validators/BooleanValidator.php b/framework/validators/BooleanValidator.php index 09b45f3c3b..91e534a08e 100644 --- a/framework/validators/BooleanValidator.php +++ b/framework/validators/BooleanValidator.php @@ -67,13 +67,13 @@ class BooleanValidator extends Validator /** * @inheritdoc */ - public function clientValidateAttribute($object, $attribute, $view) + public function clientValidateAttribute($model, $attribute, $view) { $options = [ 'trueValue' => $this->trueValue, 'falseValue' => $this->falseValue, 'message' => Yii::$app->getI18n()->format($this->message, [ - 'attribute' => $object->getAttributeLabel($attribute), + 'attribute' => $model->getAttributeLabel($attribute), 'true' => $this->trueValue, 'false' => $this->falseValue, ], Yii::$app->language), diff --git a/framework/validators/CompareValidator.php b/framework/validators/CompareValidator.php index 70bc3ffd3a..44c18e84b0 100644 --- a/framework/validators/CompareValidator.php +++ b/framework/validators/CompareValidator.php @@ -117,11 +117,11 @@ class CompareValidator extends Validator /** * @inheritdoc */ - public function validateAttribute($object, $attribute) + public function validateAttribute($model, $attribute) { - $value = $object->$attribute; + $value = $model->$attribute; if (is_array($value)) { - $this->addError($object, $attribute, Yii::t('yii', '{attribute} is invalid.')); + $this->addError($model, $attribute, Yii::t('yii', '{attribute} is invalid.')); return; } @@ -129,12 +129,12 @@ class CompareValidator extends Validator $compareLabel = $compareValue = $this->compareValue; } else { $compareAttribute = $this->compareAttribute === null ? $attribute . '_repeat' : $this->compareAttribute; - $compareValue = $object->$compareAttribute; - $compareLabel = $object->getAttributeLabel($compareAttribute); + $compareValue = $model->$compareAttribute; + $compareLabel = $model->getAttributeLabel($compareAttribute); } if (!$this->compareValues($this->operator, $this->type, $value, $compareValue)) { - $this->addError($object, $attribute, $this->message, [ + $this->addError($model, $attribute, $this->message, [ 'compareAttribute' => $compareLabel, 'compareValue' => $compareValue, ]); @@ -201,7 +201,7 @@ class CompareValidator extends Validator /** * @inheritdoc */ - public function clientValidateAttribute($object, $attribute, $view) + public function clientValidateAttribute($model, $attribute, $view) { $options = [ 'operator' => $this->operator, @@ -213,8 +213,8 @@ class CompareValidator extends Validator $compareValue = $this->compareValue; } else { $compareAttribute = $this->compareAttribute === null ? $attribute . '_repeat' : $this->compareAttribute; - $compareValue = $object->getAttributeLabel($compareAttribute); - $options['compareAttribute'] = Html::getInputId($object, $compareAttribute); + $compareValue = $model->getAttributeLabel($compareAttribute); + $options['compareAttribute'] = Html::getInputId($model, $compareAttribute); } if ($this->skipOnEmpty) { @@ -222,7 +222,7 @@ class CompareValidator extends Validator } $options['message'] = Yii::$app->getI18n()->format($this->message, [ - 'attribute' => $object->getAttributeLabel($attribute), + 'attribute' => $model->getAttributeLabel($attribute), 'compareAttribute' => $compareValue, 'compareValue' => $compareValue, ], Yii::$app->language); diff --git a/framework/validators/DateValidator.php b/framework/validators/DateValidator.php index eee0ca3db5..8ee5210281 100644 --- a/framework/validators/DateValidator.php +++ b/framework/validators/DateValidator.php @@ -94,14 +94,14 @@ class DateValidator extends Validator /** * @inheritdoc */ - public function validateAttribute($object, $attribute) + public function validateAttribute($model, $attribute) { - $value = $object->$attribute; + $value = $model->$attribute; $timestamp = $this->parseDateValue($value); if ($timestamp === false) { - $this->addError($object, $attribute, $this->message, []); + $this->addError($model, $attribute, $this->message, []); } elseif ($this->timestampAttribute !== null) { - $object->{$this->timestampAttribute} = $timestamp; + $model->{$this->timestampAttribute} = $timestamp; } } diff --git a/framework/validators/DefaultValueValidator.php b/framework/validators/DefaultValueValidator.php index 0d803111f7..d31c2f4a19 100644 --- a/framework/validators/DefaultValueValidator.php +++ b/framework/validators/DefaultValueValidator.php @@ -41,13 +41,13 @@ class DefaultValueValidator extends Validator /** * @inheritdoc */ - public function validateAttribute($object, $attribute) + public function validateAttribute($model, $attribute) { - if ($this->isEmpty($object->$attribute)) { + if ($this->isEmpty($model->$attribute)) { if ($this->value instanceof \Closure) { - $object->$attribute = call_user_func($this->value, $object, $attribute); + $model->$attribute = call_user_func($this->value, $model, $attribute); } else { - $object->$attribute = $this->value; + $model->$attribute = $this->value; } } } diff --git a/framework/validators/EmailValidator.php b/framework/validators/EmailValidator.php index ee8c77efa3..3a1f82b366 100644 --- a/framework/validators/EmailValidator.php +++ b/framework/validators/EmailValidator.php @@ -92,14 +92,14 @@ class EmailValidator extends Validator /** * @inheritdoc */ - public function clientValidateAttribute($object, $attribute, $view) + public function clientValidateAttribute($model, $attribute, $view) { $options = [ 'pattern' => new JsExpression($this->pattern), 'fullPattern' => new JsExpression($this->fullPattern), 'allowName' => $this->allowName, 'message' => Yii::$app->getI18n()->format($this->message, [ - 'attribute' => $object->getAttributeLabel($attribute), + 'attribute' => $model->getAttributeLabel($attribute), ], Yii::$app->language), 'enableIDN' => (boolean) $this->enableIDN, ]; diff --git a/framework/validators/ExistValidator.php b/framework/validators/ExistValidator.php index 20236f00dd..2657391477 100644 --- a/framework/validators/ExistValidator.php +++ b/framework/validators/ExistValidator.php @@ -81,7 +81,7 @@ class ExistValidator extends Validator /** * @inheritdoc */ - public function validateAttribute($object, $attribute) + public function validateAttribute($model, $attribute) { $targetAttribute = $this->targetAttribute === null ? $attribute : $this->targetAttribute; @@ -91,31 +91,31 @@ class ExistValidator extends Validator } $params = []; foreach ($targetAttribute as $k => $v) { - $params[$v] = is_integer($k) ? $object->$v : $object->$k; + $params[$v] = is_integer($k) ? $model->$v : $model->$k; } } else { - $params = [$targetAttribute => $object->$attribute]; + $params = [$targetAttribute => $model->$attribute]; } if (!$this->allowArray) { foreach ($params as $value) { if (is_array($value)) { - $this->addError($object, $attribute, Yii::t('yii', '{attribute} is invalid.')); + $this->addError($model, $attribute, Yii::t('yii', '{attribute} is invalid.')); return; } } } - $targetClass = $this->targetClass === null ? get_class($object) : $this->targetClass; + $targetClass = $this->targetClass === null ? get_class($model) : $this->targetClass; $query = $this->createQuery($targetClass, $params); - if (is_array($object->$attribute)) { - if ($query->count("DISTINCT [[$targetAttribute]]") != count($object->$attribute)) { - $this->addError($object, $attribute, $this->message); + if (is_array($model->$attribute)) { + if ($query->count("DISTINCT [[$targetAttribute]]") != count($model->$attribute)) { + $this->addError($model, $attribute, $this->message); } } elseif (!$query->exists()) { - $this->addError($object, $attribute, $this->message); + $this->addError($model, $attribute, $this->message); } } diff --git a/framework/validators/FileValidator.php b/framework/validators/FileValidator.php index d43119c524..16c38ba830 100644 --- a/framework/validators/FileValidator.php +++ b/framework/validators/FileValidator.php @@ -166,12 +166,12 @@ class FileValidator extends Validator /** * @inheritdoc */ - public function validateAttribute($object, $attribute) + public function validateAttribute($model, $attribute) { if ($this->maxFiles > 1) { - $files = $object->$attribute; + $files = $model->$attribute; if (!is_array($files)) { - $this->addError($object, $attribute, $this->uploadRequired); + $this->addError($model, $attribute, $this->uploadRequired); return; } @@ -180,24 +180,24 @@ class FileValidator extends Validator unset($files[$i]); } } - $object->$attribute = array_values($files); + $model->$attribute = array_values($files); if (empty($files)) { - $this->addError($object, $attribute, $this->uploadRequired); + $this->addError($model, $attribute, $this->uploadRequired); } if (count($files) > $this->maxFiles) { - $this->addError($object, $attribute, $this->tooMany, ['limit' => $this->maxFiles]); + $this->addError($model, $attribute, $this->tooMany, ['limit' => $this->maxFiles]); } else { foreach ($files as $file) { $result = $this->validateValue($file); if (!empty($result)) { - $this->addError($object, $attribute, $result[0], $result[1]); + $this->addError($model, $attribute, $result[0], $result[1]); } } } } else { - $result = $this->validateValue($object->$attribute); + $result = $this->validateValue($model->$attribute); if (!empty($result)) { - $this->addError($object, $attribute, $result[0], $result[1]); + $this->addError($model, $attribute, $result[0], $result[1]); } } } @@ -334,22 +334,22 @@ class FileValidator extends Validator /** * @inheritdoc */ - public function clientValidateAttribute($object, $attribute, $view) + public function clientValidateAttribute($model, $attribute, $view) { ValidationAsset::register($view); - $options = $this->getClientOptions($object, $attribute); + $options = $this->getClientOptions($model, $attribute); return 'yii.validation.file(attribute, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ');'; } /** * Returns the client side validation options. - * @param \yii\base\Model $object the model being validated + * @param \yii\base\Model $model the model being validated * @param string $attribute the attribute name being validated * @return array the client side validation options */ - protected function getClientOptions($object, $attribute) + protected function getClientOptions($model, $attribute) { - $label = $object->getAttributeLabel($attribute); + $label = $model->getAttributeLabel($attribute); $options = []; if ($this->message !== null) { diff --git a/framework/validators/FilterValidator.php b/framework/validators/FilterValidator.php index edc171d037..bd0404e695 100644 --- a/framework/validators/FilterValidator.php +++ b/framework/validators/FilterValidator.php @@ -65,11 +65,11 @@ class FilterValidator extends Validator /** * @inheritdoc */ - public function validateAttribute($object, $attribute) + public function validateAttribute($model, $attribute) { - $value = $object->$attribute; + $value = $model->$attribute; if (!$this->skipOnArray || !is_array($value)) { - $object->$attribute = call_user_func($this->filter, $value); + $model->$attribute = call_user_func($this->filter, $value); } } } diff --git a/framework/validators/ImageValidator.php b/framework/validators/ImageValidator.php index 6643c6ceb0..9fa38d5efd 100644 --- a/framework/validators/ImageValidator.php +++ b/framework/validators/ImageValidator.php @@ -162,21 +162,21 @@ class ImageValidator extends FileValidator /** * @inheritdoc */ - public function clientValidateAttribute($object, $attribute, $view) + public function clientValidateAttribute($model, $attribute, $view) { ValidationAsset::register($view); - $options = $this->getClientOptions($object, $attribute); + $options = $this->getClientOptions($model, $attribute); return 'yii.validation.image(attribute, messages, ' . json_encode($options, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ', deferred);'; } /** * @inheritdoc */ - protected function getClientOptions($object, $attribute) + protected function getClientOptions($model, $attribute) { - $options = parent::getClientOptions($object, $attribute); + $options = parent::getClientOptions($model, $attribute); - $label = $object->getAttributeLabel($attribute); + $label = $model->getAttributeLabel($attribute); if ($this->notImage !== null) { $options['notImage'] = Yii::$app->getI18n()->format($this->notImage, [ diff --git a/framework/validators/InlineValidator.php b/framework/validators/InlineValidator.php index 0e5cd33919..c4f4b950cf 100644 --- a/framework/validators/InlineValidator.php +++ b/framework/validators/InlineValidator.php @@ -58,11 +58,11 @@ class InlineValidator extends Validator /** * @inheritdoc */ - public function validateAttribute($object, $attribute) + public function validateAttribute($model, $attribute) { $method = $this->method; if (is_string($method)) { - $method = [$object, $method]; + $method = [$model, $method]; } call_user_func($method, $attribute, $this->params); } @@ -70,12 +70,12 @@ class InlineValidator extends Validator /** * @inheritdoc */ - public function clientValidateAttribute($object, $attribute, $view) + public function clientValidateAttribute($model, $attribute, $view) { if ($this->clientValidate !== null) { $method = $this->clientValidate; if (is_string($method)) { - $method = [$object, $method]; + $method = [$model, $method]; } return call_user_func($method, $attribute, $this->params); diff --git a/framework/validators/NumberValidator.php b/framework/validators/NumberValidator.php index e299e96eca..bd7660cdc9 100644 --- a/framework/validators/NumberValidator.php +++ b/framework/validators/NumberValidator.php @@ -75,22 +75,22 @@ class NumberValidator extends Validator /** * @inheritdoc */ - public function validateAttribute($object, $attribute) + public function validateAttribute($model, $attribute) { - $value = $object->$attribute; + $value = $model->$attribute; if (is_array($value)) { - $this->addError($object, $attribute, $this->message); + $this->addError($model, $attribute, $this->message); return; } $pattern = $this->integerOnly ? $this->integerPattern : $this->numberPattern; if (!preg_match($pattern, "$value")) { - $this->addError($object, $attribute, $this->message); + $this->addError($model, $attribute, $this->message); } if ($this->min !== null && $value < $this->min) { - $this->addError($object, $attribute, $this->tooSmall, ['min' => $this->min]); + $this->addError($model, $attribute, $this->tooSmall, ['min' => $this->min]); } if ($this->max !== null && $value > $this->max) { - $this->addError($object, $attribute, $this->tooBig, ['max' => $this->max]); + $this->addError($model, $attribute, $this->tooBig, ['max' => $this->max]); } } @@ -117,9 +117,9 @@ class NumberValidator extends Validator /** * @inheritdoc */ - public function clientValidateAttribute($object, $attribute, $view) + public function clientValidateAttribute($model, $attribute, $view) { - $label = $object->getAttributeLabel($attribute); + $label = $model->getAttributeLabel($attribute); $options = [ 'pattern' => new JsExpression($this->integerOnly ? $this->integerPattern : $this->numberPattern), diff --git a/framework/validators/RangeValidator.php b/framework/validators/RangeValidator.php index 370a1d5554..04f37b293c 100644 --- a/framework/validators/RangeValidator.php +++ b/framework/validators/RangeValidator.php @@ -79,7 +79,7 @@ class RangeValidator extends Validator /** * @inheritdoc */ - public function clientValidateAttribute($object, $attribute, $view) + public function clientValidateAttribute($model, $attribute, $view) { $range = []; foreach ($this->range as $value) { @@ -89,7 +89,7 @@ class RangeValidator extends Validator 'range' => $range, 'not' => $this->not, 'message' => Yii::$app->getI18n()->format($this->message, [ - 'attribute' => $object->getAttributeLabel($attribute), + 'attribute' => $model->getAttributeLabel($attribute), ], Yii::$app->language), ]; if ($this->skipOnEmpty) { diff --git a/framework/validators/RegularExpressionValidator.php b/framework/validators/RegularExpressionValidator.php index dee81ff12f..acf7482db5 100644 --- a/framework/validators/RegularExpressionValidator.php +++ b/framework/validators/RegularExpressionValidator.php @@ -62,7 +62,7 @@ class RegularExpressionValidator extends Validator /** * @inheritdoc */ - public function clientValidateAttribute($object, $attribute, $view) + public function clientValidateAttribute($model, $attribute, $view) { $pattern = $this->pattern; $pattern = preg_replace('/\\\\x\{?([0-9a-fA-F]+)\}?/', '\u$1', $pattern); @@ -82,7 +82,7 @@ class RegularExpressionValidator extends Validator 'pattern' => new JsExpression($pattern), 'not' => $this->not, 'message' => Yii::$app->getI18n()->format($this->message, [ - 'attribute' => $object->getAttributeLabel($attribute), + 'attribute' => $model->getAttributeLabel($attribute), ], Yii::$app->language), ]; if ($this->skipOnEmpty) { diff --git a/framework/validators/RequiredValidator.php b/framework/validators/RequiredValidator.php index 3b57876a09..e416b10864 100644 --- a/framework/validators/RequiredValidator.php +++ b/framework/validators/RequiredValidator.php @@ -86,7 +86,7 @@ class RequiredValidator extends Validator /** * @inheritdoc */ - public function clientValidateAttribute($object, $attribute, $view) + public function clientValidateAttribute($model, $attribute, $view) { $options = []; if ($this->requiredValue !== null) { @@ -102,7 +102,7 @@ class RequiredValidator extends Validator } $options['message'] = Yii::$app->getI18n()->format($options['message'], [ - 'attribute' => $object->getAttributeLabel($attribute), + 'attribute' => $model->getAttributeLabel($attribute), ], Yii::$app->language); ValidationAsset::register($view); diff --git a/framework/validators/SafeValidator.php b/framework/validators/SafeValidator.php index fcb8440ec5..846d63e68a 100644 --- a/framework/validators/SafeValidator.php +++ b/framework/validators/SafeValidator.php @@ -18,7 +18,7 @@ class SafeValidator extends Validator /** * @inheritdoc */ - public function validateAttribute($object, $attribute) + public function validateAttribute($model, $attribute) { } } diff --git a/framework/validators/StringValidator.php b/framework/validators/StringValidator.php index 0ca40c6c69..a9a34b24db 100644 --- a/framework/validators/StringValidator.php +++ b/framework/validators/StringValidator.php @@ -96,12 +96,12 @@ class StringValidator extends Validator /** * @inheritdoc */ - public function validateAttribute($object, $attribute) + public function validateAttribute($model, $attribute) { - $value = $object->$attribute; + $value = $model->$attribute; if (!is_string($value)) { - $this->addError($object, $attribute, $this->message); + $this->addError($model, $attribute, $this->message); return; } @@ -109,13 +109,13 @@ class StringValidator extends Validator $length = mb_strlen($value, $this->encoding); if ($this->min !== null && $length < $this->min) { - $this->addError($object, $attribute, $this->tooShort, ['min' => $this->min]); + $this->addError($model, $attribute, $this->tooShort, ['min' => $this->min]); } if ($this->max !== null && $length > $this->max) { - $this->addError($object, $attribute, $this->tooLong, ['max' => $this->max]); + $this->addError($model, $attribute, $this->tooLong, ['max' => $this->max]); } if ($this->length !== null && $length !== $this->length) { - $this->addError($object, $attribute, $this->notEqual, ['length' => $this->length]); + $this->addError($model, $attribute, $this->notEqual, ['length' => $this->length]); } } @@ -146,9 +146,9 @@ class StringValidator extends Validator /** * @inheritdoc */ - public function clientValidateAttribute($object, $attribute, $view) + public function clientValidateAttribute($model, $attribute, $view) { - $label = $object->getAttributeLabel($attribute); + $label = $model->getAttributeLabel($attribute); $options = [ 'message' => Yii::$app->getI18n()->format($this->message, [ diff --git a/framework/validators/UniqueValidator.php b/framework/validators/UniqueValidator.php index 9b0388a9f3..eb90494a9e 100644 --- a/framework/validators/UniqueValidator.php +++ b/framework/validators/UniqueValidator.php @@ -74,24 +74,24 @@ class UniqueValidator extends Validator /** * @inheritdoc */ - public function validateAttribute($object, $attribute) + public function validateAttribute($model, $attribute) { /* @var $targetClass ActiveRecordInterface */ - $targetClass = $this->targetClass === null ? get_class($object) : $this->targetClass; + $targetClass = $this->targetClass === null ? get_class($model) : $this->targetClass; $targetAttribute = $this->targetAttribute === null ? $attribute : $this->targetAttribute; if (is_array($targetAttribute)) { $params = []; foreach ($targetAttribute as $k => $v) { - $params[$v] = is_integer($k) ? $object->$v : $object->$k; + $params[$v] = is_integer($k) ? $model->$v : $model->$k; } } else { - $params = [$targetAttribute => $object->$attribute]; + $params = [$targetAttribute => $model->$attribute]; } foreach ($params as $value) { if (is_array($value)) { - $this->addError($object, $attribute, Yii::t('yii', '{attribute} is invalid.')); + $this->addError($model, $attribute, Yii::t('yii', '{attribute} is invalid.')); return; } @@ -106,14 +106,14 @@ class UniqueValidator extends Validator $query->andWhere($this->filter); } - if (!$object instanceof ActiveRecordInterface || $object->getIsNewRecord()) { - // if current $object isn't in the database yet then it's OK just to call exists() + if (!$model instanceof ActiveRecordInterface || $model->getIsNewRecord()) { + // if current $model isn't in the database yet then it's OK just to call exists() $exists = $query->exists(); } else { - // if current $object is in the database already we can't use exists() - /* @var $objects ActiveRecordInterface[] */ - $objects = $query->limit(2)->all(); - $n = count($objects); + // if current $model is in the database already we can't use exists() + /* @var $models ActiveRecordInterface[] */ + $models = $query->limit(2)->all(); + $n = count($models); if ($n === 1) { $keys = array_keys($params); $pks = $targetClass::primaryKey(); @@ -121,10 +121,10 @@ class UniqueValidator extends Validator sort($pks); if ($keys === $pks) { // primary key is modified and not unique - $exists = $object->getOldPrimaryKey() != $object->getPrimaryKey(); + $exists = $model->getOldPrimaryKey() != $model->getPrimaryKey(); } else { // non-primary key, need to exclude the current record based on PK - $exists = $objects[0]->getPrimaryKey() != $object->getOldPrimaryKey(); + $exists = $models[0]->getPrimaryKey() != $model->getOldPrimaryKey(); } } else { $exists = $n > 1; @@ -132,7 +132,7 @@ class UniqueValidator extends Validator } if ($exists) { - $this->addError($object, $attribute, $this->message); + $this->addError($model, $attribute, $this->message); } } } diff --git a/framework/validators/UrlValidator.php b/framework/validators/UrlValidator.php index 4c2c0a5291..11b67cd46c 100644 --- a/framework/validators/UrlValidator.php +++ b/framework/validators/UrlValidator.php @@ -66,14 +66,14 @@ class UrlValidator extends Validator /** * @inheritdoc */ - public function validateAttribute($object, $attribute) + public function validateAttribute($model, $attribute) { - $value = $object->$attribute; + $value = $model->$attribute; $result = $this->validateValue($value); if (!empty($result)) { - $this->addError($object, $attribute, $result[0], $result[1]); + $this->addError($model, $attribute, $result[0], $result[1]); } elseif ($this->defaultScheme !== null && strpos($value, '://') === false) { - $object->$attribute = $this->defaultScheme . '://' . $value; + $model->$attribute = $this->defaultScheme . '://' . $value; } } @@ -111,7 +111,7 @@ class UrlValidator extends Validator /** * @inheritdoc */ - public function clientValidateAttribute($object, $attribute, $view) + public function clientValidateAttribute($model, $attribute, $view) { if (strpos($this->pattern, '{schemes}') !== false) { $pattern = str_replace('{schemes}', '(' . implode('|', $this->validSchemes) . ')', $this->pattern); @@ -122,7 +122,7 @@ class UrlValidator extends Validator $options = [ 'pattern' => new JsExpression($pattern), 'message' => Yii::$app->getI18n()->format($this->message, [ - 'attribute' => $object->getAttributeLabel($attribute), + 'attribute' => $model->getAttributeLabel($attribute), ], Yii::$app->language), 'enableIDN' => (boolean) $this->enableIDN, ];