From 332030325fbad38a64c5e60980d3b14b6434d6dd Mon Sep 17 00:00:00 2001 From: Yakir Sitbon Date: Fri, 18 Oct 2013 09:48:27 +0000 Subject: [PATCH] Convert to short syntax (array) --- controllers/SiteController.php | 60 +++++++++++++++++----------------- models/ContactForm.php | 14 ++++---- models/LoginForm.php | 10 +++--- models/User.php | 12 +++---- 4 files changed, 48 insertions(+), 48 deletions(-) diff --git a/controllers/SiteController.php b/controllers/SiteController.php index e243223..f369e3b 100644 --- a/controllers/SiteController.php +++ b/controllers/SiteController.php @@ -13,43 +13,43 @@ class SiteController extends Controller { public function behaviors() { - return array( - 'access' => array( + return [ + 'access' => [ 'class' => AccessControl::className(), - 'only' => array('login', 'logout'), - 'rules' => array( - array( - 'actions' => array('login'), + 'only' => ['login', 'logout'], + 'rules' => [ + [ + 'actions' => ['login'], 'allow' => true, - 'roles' => array('?'), - ), - array( - 'actions' => array('logout'), + 'roles' => ['?'], + ], + [ + 'actions' => ['logout'], 'allow' => true, - 'roles' => array('@'), - ), - ), - ), - 'verbs' => array( + 'roles' => ['@'], + ], + ], + ], + 'verbs' => [ 'class' => VerbFilter::className(), - 'actions' => array( - 'logout' => array('post'), - ), - ), - ); + 'actions' => [ + 'logout' => ['post'], + ], + ], + ]; } public function actions() { - return array( - 'error' => array( + return [ + 'error' => [ 'class' => 'yii\web\ErrorAction', - ), - 'captcha' => array( + ], + 'captcha' => [ 'class' => 'yii\captcha\CaptchaAction', 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, - ), - ); + ], + ]; } public function actionIndex() @@ -63,9 +63,9 @@ class SiteController extends Controller if ($model->load($_POST) && $model->login()) { return $this->goBack(); } else { - return $this->render('login', array( + return $this->render('login', [ 'model' => $model, - )); + ]); } } @@ -82,9 +82,9 @@ class SiteController extends Controller Yii::$app->session->setFlash('contactFormSubmitted'); return $this->refresh(); } else { - return $this->render('contact', array( + return $this->render('contact', [ 'model' => $model, - )); + ]); } } diff --git a/models/ContactForm.php b/models/ContactForm.php index 7b713a1..f42cd53 100644 --- a/models/ContactForm.php +++ b/models/ContactForm.php @@ -20,14 +20,14 @@ class ContactForm extends Model */ public function rules() { - return array( + return [ // name, email, subject and body are required - array('name, email, subject, body', 'required'), + ['name, email, subject, body', 'required'], // email has to be a valid email address - array('email', 'email'), + ['email', 'email'], // verifyCode needs to be entered correctly - array('verifyCode', 'captcha'), - ); + ['verifyCode', 'captcha'], + ]; } /** @@ -35,9 +35,9 @@ class ContactForm extends Model */ public function attributeLabels() { - return array( + return [ 'verifyCode' => 'Verification Code', - ); + ]; } /** diff --git a/models/LoginForm.php b/models/LoginForm.php index 5ba1dc6..339cf31 100644 --- a/models/LoginForm.php +++ b/models/LoginForm.php @@ -19,14 +19,14 @@ class LoginForm extends Model */ public function rules() { - return array( + return [ // username and password are both required - array('username, password', 'required'), + ['username, password', 'required'], // password is validated by validatePassword() - array('password', 'validatePassword'), + ['password', 'validatePassword'], // rememberMe must be a boolean value - array('rememberMe', 'boolean'), - ); + ['rememberMe', 'boolean'], + ]; } /** diff --git a/models/User.php b/models/User.php index e1088a0..085cda2 100644 --- a/models/User.php +++ b/models/User.php @@ -9,20 +9,20 @@ class User extends \yii\base\Object implements \yii\web\IdentityInterface public $password; public $authKey; - private static $users = array( - '100' => array( + private static $users = [ + '100' => [ 'id' => '100', 'username' => 'admin', 'password' => 'admin', 'authKey' => 'test100key', - ), - '101' => array( + ], + '101' => [ 'id' => '101', 'username' => 'demo', 'password' => 'demo', 'authKey' => 'test101key', - ), - ); + ], + ]; public static function findIdentity($id) {