Commit ecc557ef by slavcodev

Refactor all models to new rules format

parent 3cdd78ca
...@@ -21,11 +21,11 @@ class LoginForm extends Model ...@@ -21,11 +21,11 @@ class LoginForm extends Model
{ {
return [ return [
// username and password are both required // username and password are both required
['username, password', 'required'], [['username', 'password'], 'required'],
// password is validated by validatePassword() // password is validated by validatePassword()
['password', 'validatePassword'], [['password'], 'validatePassword'],
// rememberMe must be a boolean value // rememberMe must be a boolean value
['rememberMe', 'boolean'], [['rememberMe'], 'boolean'],
]; ];
} }
......
...@@ -104,18 +104,18 @@ class User extends ActiveRecord implements IdentityInterface ...@@ -104,18 +104,18 @@ class User extends ActiveRecord implements IdentityInterface
public function rules() public function rules()
{ {
return [ return [
['username', 'filter', 'filter' => 'trim'], [['username'], 'filter', 'filter' => 'trim'],
['username', 'required'], [['username'], 'required'],
['username', 'string', 'min' => 2, 'max' => 255], [['username'], 'string', 'min' => 2, 'max' => 255],
['email', 'filter', 'filter' => 'trim'], [['email'], 'filter', 'filter' => 'trim'],
['email', 'required'], [['email'], 'required'],
['email', 'email'], [['email'], 'email'],
['email', 'unique', 'message' => 'This email address has already been taken.', 'on' => 'signup'], [['email'], 'unique', 'message' => 'This email address has already been taken.', 'on' => 'signup'],
['email', 'exist', 'message' => 'There is no user with such email.', 'on' => 'requestPasswordResetToken'], [['email'], 'exist', 'message' => 'There is no user with such email.', 'on' => 'requestPasswordResetToken'],
['password', 'required'], [['password'], 'required'],
['password', 'string', 'min' => 6], [['password'], 'string', 'min' => 6],
]; ];
} }
......
...@@ -23,11 +23,11 @@ class ContactForm extends Model ...@@ -23,11 +23,11 @@ class ContactForm extends Model
{ {
return [ return [
// name, email, subject and body are required // name, email, subject and body are required
['name, email, subject, body', 'required'], [['name', 'email', 'subject', 'body'], 'required'],
// email has to be a valid email address // email has to be a valid email address
['email', 'email'], [['email'], 'email'],
// verifyCode needs to be entered correctly // verifyCode needs to be entered correctly
['verifyCode', 'captcha'], [['verifyCode'], 'captcha'],
]; ];
} }
......
...@@ -23,11 +23,11 @@ class ContactForm extends Model ...@@ -23,11 +23,11 @@ class ContactForm extends Model
{ {
return [ return [
// name, email, subject and body are required // name, email, subject and body are required
['name, email, subject, body', 'required'], [['name', 'email', 'subject', 'body'], 'required'],
// email has to be a valid email address // email has to be a valid email address
['email', 'email'], [['email'], 'email'],
// verifyCode needs to be entered correctly // verifyCode needs to be entered correctly
['verifyCode', 'captcha'], [['verifyCode'], 'captcha'],
]; ];
} }
......
...@@ -21,11 +21,11 @@ class LoginForm extends Model ...@@ -21,11 +21,11 @@ class LoginForm extends Model
{ {
return [ return [
// username and password are both required // username and password are both required
['username, password', 'required'], [['username', 'password'], 'required'],
// password is validated by validatePassword() // password is validated by validatePassword()
['password', 'validatePassword'], [['password'], 'validatePassword'],
// rememberMe must be a boolean value // rememberMe must be a boolean value
['rememberMe', 'boolean'], [['rememberMe'], 'boolean'],
]; ];
} }
......
...@@ -178,8 +178,8 @@ abstract class Generator extends Model ...@@ -178,8 +178,8 @@ abstract class Generator extends Model
public function rules() public function rules()
{ {
return [ return [
['template', 'required', 'message' => 'A code template must be selected.'], [['template'], 'required', 'message' => 'A code template must be selected.'],
['template', 'validateTemplate'], [['template'], 'validateTemplate'],
]; ];
} }
......
...@@ -69,12 +69,12 @@ class Generator extends \yii\gii\Generator ...@@ -69,12 +69,12 @@ class Generator extends \yii\gii\Generator
public function rules() public function rules()
{ {
return array_merge(parent::rules(), [ return array_merge(parent::rules(), [
['controller, actions, baseClass, ns', 'filter', 'filter' => 'trim'], [['controller', 'actions', 'baseClass', 'ns'], 'filter', 'filter' => 'trim'],
['controller, baseClass', 'required'], [['controller', 'baseClass'], 'required'],
['controller', 'match', 'pattern' => '/^[a-z\\-\\/]*$/', 'message' => 'Only a-z, dashes (-) and slashes (/) are allowed.'], [['controller'], 'match', 'pattern' => '/^[a-z\\-\\/]*$/', 'message' => 'Only a-z, dashes (-) and slashes (/) are allowed.'],
['actions', 'match', 'pattern' => '/^[a-z\\-,\\s]*$/', 'message' => 'Only a-z, dashes (-), spaces and commas are allowed.'], [['actions'], 'match', 'pattern' => '/^[a-z\\-,\\s]*$/', 'message' => 'Only a-z, dashes (-), spaces and commas are allowed.'],
['baseClass', 'match', 'pattern' => '/^[\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'], [['baseClass'], 'match', 'pattern' => '/^[\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'],
['ns', 'match', 'pattern' => '/^[\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'], [['ns'], 'match', 'pattern' => '/^[\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'],
]); ]);
} }
......
...@@ -42,17 +42,17 @@ class Generator extends \yii\gii\Generator ...@@ -42,17 +42,17 @@ class Generator extends \yii\gii\Generator
public function rules() public function rules()
{ {
return array_merge(parent::rules(), [ return array_merge(parent::rules(), [
['moduleID, controllerClass, modelClass, searchModelClass, baseControllerClass', 'filter', 'filter' => 'trim'], [['moduleID', 'controllerClass', 'modelClass', 'searchModelClass', 'baseControllerClass'], 'filter', 'filter' => 'trim'],
['modelClass, searchModelClass, controllerClass, baseControllerClass, indexWidgetType', 'required'], [['modelClass', 'searchModelClass', 'controllerClass', 'baseControllerClass', 'indexWidgetType'], 'required'],
['searchModelClass', 'compare', 'compareAttribute' => 'modelClass', 'operator' => '!==', 'message' => 'Search Model Class must not be equal to Model Class.'], [['searchModelClass'], 'compare', 'compareAttribute' => 'modelClass', 'operator' => '!==', 'message' => 'Search Model Class must not be equal to Model Class.'],
['modelClass, controllerClass, baseControllerClass, searchModelClass', 'match', 'pattern' => '/^[\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'], [['modelClass', 'controllerClass', 'baseControllerClass', 'searchModelClass'], 'match', 'pattern' => '/^[\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'],
['modelClass', 'validateClass', 'params' => ['extends' => ActiveRecord::className()]], [['modelClass'], 'validateClass', 'params' => ['extends' => ActiveRecord::className()]],
['baseControllerClass', 'validateClass', 'params' => ['extends' => Controller::className()]], [['baseControllerClass'], 'validateClass', 'params' => ['extends' => Controller::className()]],
['controllerClass', 'match', 'pattern' => '/Controller$/', 'message' => 'Controller class name must be suffixed with "Controller".'], [['controllerClass'], 'match', 'pattern' => '/Controller$/', 'message' => 'Controller class name must be suffixed with "Controller".'],
['controllerClass, searchModelClass', 'validateNewClass'], [['controllerClass', 'searchModelClass'], 'validateNewClass'],
['indexWidgetType', 'in', 'range' => ['grid', 'list']], [['indexWidgetType'], 'in', 'range' => ['grid', 'list']],
['modelClass', 'validateModelClass'], [['modelClass'], 'validateModelClass'],
['moduleID', 'validateModuleID'], [['moduleID'], 'validateModuleID'],
]); ]);
} }
......
...@@ -60,14 +60,14 @@ class Generator extends \yii\gii\Generator ...@@ -60,14 +60,14 @@ class Generator extends \yii\gii\Generator
public function rules() public function rules()
{ {
return array_merge(parent::rules(), [ return array_merge(parent::rules(), [
['modelClass, viewName, scenarioName, viewPath', 'filter', 'filter' => 'trim'], [['modelClass', 'viewName', 'scenarioName', 'viewPath'], 'filter', 'filter' => 'trim'],
['modelClass, viewName, viewPath', 'required'], [['modelClass', 'viewName', 'viewPath'], 'required'],
['modelClass', 'match', 'pattern' => '/^[\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'], [['modelClass'], 'match', 'pattern' => '/^[\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'],
['modelClass', 'validateClass', 'params' => ['extends' => Model::className()]], [['modelClass'], 'validateClass', 'params' => ['extends' => Model::className()]],
['viewName', 'match', 'pattern' => '/^\w+[\\-\\/\w]*$/', 'message' => 'Only word characters, dashes and slashes are allowed.'], [['viewName'], 'match', 'pattern' => '/^\w+[\\-\\/\w]*$/', 'message' => 'Only word characters, dashes and slashes are allowed.'],
['viewPath', 'match', 'pattern' => '/^@?\w+[\\-\\/\w]*$/', 'message' => 'Only word characters, dashes, slashes and @ are allowed.'], [['viewPath'], 'match', 'pattern' => '/^@?\w+[\\-\\/\w]*$/', 'message' => 'Only word characters, dashes, slashes and @ are allowed.'],
['viewPath', 'validateViewPath'], [['viewPath'], 'validateViewPath'],
['scenarioName', 'match', 'pattern' => '/^[\w\\-]+$/', 'message' => 'Only word characters and dashes are allowed.'], [['scenarioName'], 'match', 'pattern' => '/^[\w\\-]+$/', 'message' => 'Only word characters and dashes are allowed.'],
]); ]);
} }
......
...@@ -53,17 +53,17 @@ class Generator extends \yii\gii\Generator ...@@ -53,17 +53,17 @@ class Generator extends \yii\gii\Generator
public function rules() public function rules()
{ {
return array_merge(parent::rules(), [ return array_merge(parent::rules(), [
['db, ns, tableName, modelClass, baseClass', 'filter', 'filter' => 'trim'], [['db', 'ns', 'tableName', 'modelClass', 'baseClass'], 'filter', 'filter' => 'trim'],
['db, ns, tableName, baseClass', 'required'], [['db', 'ns', 'tableName', 'baseClass'], 'required'],
['db, modelClass', 'match', 'pattern' => '/^\w+$/', 'message' => 'Only word characters are allowed.'], [['db', 'modelClass'], 'match', 'pattern' => '/^\w+$/', 'message' => 'Only word characters are allowed.'],
['ns, baseClass', 'match', 'pattern' => '/^[\w\\\\]+$/', 'message' => 'Only word characters and backslashes are allowed.'], [['ns', 'baseClass'], 'match', 'pattern' => '/^[\w\\\\]+$/', 'message' => 'Only word characters and backslashes are allowed.'],
['tableName', 'match', 'pattern' => '/^(\w+\.)?([\w\*]+)$/', 'message' => 'Only word characters, and optionally an asterisk and/or a dot are allowed.'], [['tableName'], 'match', 'pattern' => '/^(\w+\.)?([\w\*]+)$/', 'message' => 'Only word characters, and optionally an asterisk and/or a dot are allowed.'],
['db', 'validateDb'], [['db'], 'validateDb'],
['ns', 'validateNamespace'], [['ns'], 'validateNamespace'],
['tableName', 'validateTableName'], [['tableName'], 'validateTableName'],
['modelClass', 'validateModelClass', 'skipOnEmpty' => false], [['modelClass'], 'validateModelClass', 'skipOnEmpty' => false],
['baseClass', 'validateClass', 'params' => ['extends' => ActiveRecord::className()]], [['baseClass'], 'validateClass', 'params' => ['extends' => ActiveRecord::className()]],
['generateRelations, generateLabelsFromComments', 'boolean'], [['generateRelations', 'generateLabelsFromComments'], 'boolean'],
]); ]);
} }
......
...@@ -45,11 +45,11 @@ class Generator extends \yii\gii\Generator ...@@ -45,11 +45,11 @@ class Generator extends \yii\gii\Generator
public function rules() public function rules()
{ {
return array_merge(parent::rules(), [ return array_merge(parent::rules(), [
['moduleID, moduleClass', 'filter', 'filter' => 'trim'], [['moduleID', 'moduleClass'], 'filter', 'filter' => 'trim'],
['moduleID, moduleClass', 'required'], [['moduleID', 'moduleClass'], 'required'],
['moduleID', 'match', 'pattern' => '/^[\w\\-]+$/', 'message' => 'Only word characters and dashes are allowed.'], [['moduleID'], 'match', 'pattern' => '/^[\w\\-]+$/', 'message' => 'Only word characters and dashes are allowed.'],
['moduleClass', 'match', 'pattern' => '/^[\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'], [['moduleClass'], 'match', 'pattern' => '/^[\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'],
['moduleClass', 'validateModuleClass'], [['moduleClass'], 'validateModuleClass'],
]); ]);
} }
......
...@@ -14,9 +14,9 @@ class Singer extends Model ...@@ -14,9 +14,9 @@ class Singer extends Model
public function rules() public function rules()
{ {
return [ return [
['lastName', 'default', 'value' => 'Lennon'], [['lastName'], 'default', 'value' => 'Lennon'],
['lastName', 'required'], [['lastName'], 'required'],
['underscore_style', 'yii\captcha\CaptchaValidator'], [['underscore_style'], 'yii\captcha\CaptchaValidator'],
]; ];
} }
} }
...@@ -28,8 +28,8 @@ class FakedValidationModel extends Model ...@@ -28,8 +28,8 @@ class FakedValidationModel extends Model
public function rules() public function rules()
{ {
return [ return [
['val_attr_a, val_attr_b', 'required', 'on' => 'reqTest'], [['val_attr_a', 'val_attr_b'], 'required', 'on' => 'reqTest'],
['val_attr_c', 'integer'], [['val_attr_c'], 'integer'],
]; ];
} }
...@@ -60,4 +60,4 @@ class FakedValidationModel extends Model ...@@ -60,4 +60,4 @@ class FakedValidationModel extends Model
{ {
return $attr; return $attr;
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment