Skip to content

Commit 9e696d7

Browse files
author
Samuel Akopyan
committed
Changed array() with []
1 parent 0da93ce commit 9e696d7

File tree

6 files changed

+478
-457
lines changed

6 files changed

+478
-457
lines changed

demos/login-system/protected/modules/setup/controllers/SetupController.php

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ public function __construct()
4949
$this->_cRequest = A::app()->getRequest();
5050
$this->_pdoExtensionRequired = true;
5151
$this->_configMain = include(APPHP_PATH . '/protected/data/config.main.tpl');
52-
$this->_languages = array('en' => 'English', 'es' => utf8_encode('Español'), 'de' => utf8_encode('Deutsch'));
53-
54-
$this->_view->errorField = '';
52+
$this->_languages = ['en' => 'English', 'es' => utf8_encode('Español'), 'de' => utf8_encode('Deutsch')];
53+
54+
$this->_view->errorField = '';
5555
$this->_view->_programName = isset($this->_configMain['name']) ? $this->_configMain['name'] : '';
5656
$this->_view->_programVersion = isset($this->_configMain['version']) ? $this->_configMain['version'] : '';
5757

@@ -280,22 +280,22 @@ public function databaseAction()
280280
$dbConnectTypes = ['host' => A::t('setup', 'host'), 'socket' => A::t('setup', 'socket')];
281281
$msg = '';
282282

283-
$separatorGeneralFields = array(
283+
$separatorGeneralFields = [
284284
'separatorInfo' => ['legend' => 'General Settings'],
285285
'setupType' => ['type' => 'dropdownlist', 'value' => $this->_view->setupType, 'title' => A::t('setup', 'Setup Type'), 'mandatoryStar' => false, 'data' => array('install' => A::t('setup', 'New Installation'), 'update' => A::t('setup', 'Update')), 'htmlOptions' => [], 'validation' => array('required' => true, 'type' => 'text', 'source' => array('install'))],
286286
'dbDriver' => ['type' => 'dropdownlist', 'value' => $this->_view->dbDriver, 'title' => A::t('setup', 'Database Driver'), 'mandatoryStar' => true, 'data' => $dbDrivers, 'htmlOptions' => array('style' => 'width:85px'), 'validation' => array('required' => true, 'type' => 'text', 'source' => array_keys($dbDrivers))],
287287
'dbPrefix' => ['type' => 'textbox', 'value' => $this->_view->dbPrefix, 'title' => A::t('setup', 'Database (tables) Prefix'), 'mandatoryStar' => false, 'htmlOptions' => array('maxLength' => '10', 'autocomplete' => 'off'), 'validation' => array('required' => false, 'type' => 'variable')],
288-
);
289-
$separatorConenctionSettingsFields = array(
290-
'separatorInfo' => array('legend' => 'Connection Settings'),
291-
'dbConnectType' => array('type' => 'dropdownlist', 'value' => $this->_view->dbConnectType, 'title' => A::t('setup', 'Connection Type'), 'mandatoryStar' => true, 'data' => $dbConnectTypes, 'htmlOptions' => array('style' => 'width:85px'), 'validation' => array('required' => true, 'type' => 'text', 'source' => array_keys($dbConnectTypes))),
292-
'dbSocket' => array('type' => 'textbox', 'value' => $this->_view->dbSocket, 'title' => A::t('setup', 'Database Socket'), 'mandatoryStar' => true, 'htmlOptions' => array('maxLength' => '60', 'autocomplete' => 'off', 'placeholder' => '/tmp/mysql.sock'), 'validation' => array('required' => ($this->_view->dbConnectType == 'socket' ? true : false), 'type' => 'text'), 'disabled' => ($this->_view->dbConnectType == 'socket' ? false : true)),
293-
'dbHost' => array('type' => 'textbox', 'value' => $this->_view->dbHost, 'title' => A::t('setup', 'Database Host'), 'mandatoryStar' => true, 'htmlOptions' => array('maxLength' => '60', 'autocomplete' => 'off', 'placeholder' => 'e.g. localhost'), 'validation' => array('required' => ($this->_view->dbConnectType == 'host' ? true : false), 'type' => 'text'), 'disabled' => ($this->_view->dbConnectType == 'host' ? false : true)),
294-
'dbPort' => array('type' => 'textbox', 'value' => $this->_view->dbPort, 'title' => A::t('setup', 'Database Port'), 'mandatoryStar' => false, 'htmlOptions' => array('maxLength' => '10', 'autocomplete' => 'off', 'placeholder' => 'e.g. 3306', 'style' => 'width:80px'), 'validation' => array('required' => false, 'type' => 'integer'), 'disabled' => ($this->_view->dbConnectType == 'host' ? false : true)),
295-
'dbName' => array('type' => 'textbox', 'value' => $this->_view->dbName, 'title' => A::t('setup', 'Database Name'), 'mandatoryStar' => true, 'htmlOptions' => array('maxLength' => '30', 'autocomplete' => 'off'), 'validation' => array('required' => true, 'type' => 'text')),
296-
'dbUser' => array('type' => 'textbox', 'value' => $this->_view->dbUser, 'title' => A::t('setup', 'Database User'), 'mandatoryStar' => true, 'htmlOptions' => array('maxLength' => '30', 'autocomplete' => 'off'), 'validation' => array('required' => true, 'type' => 'text')),
297-
'dbPassword' => array('type' => 'password', 'value' => $this->_view->dbPassword, 'title' => A::t('setup', 'Database Password'), 'mandatoryStar' => false, 'htmlOptions' => array('maxLength' => '20', 'autocomplete' => 'off', 'id' => 'db_password'), 'validation' => array('required' => false, 'type' => 'text'), 'appendCode' => '<div for="db_password" class="toggle_password" data-field="db_password"></div>'),
298-
);
288+
];
289+
$separatorConenctionSettingsFields = [
290+
'separatorInfo' => ['legend' => 'Connection Settings'],
291+
'dbConnectType' => ['type' => 'dropdownlist', 'value' => $this->_view->dbConnectType, 'title' => A::t('setup', 'Connection Type'), 'mandatoryStar' => true, 'data' => $dbConnectTypes, 'htmlOptions' => array('style' => 'width:85px'), 'validation' => ['required' => true, 'type' => 'text', 'source' => array_keys($dbConnectTypes)]],
292+
'dbSocket' => ['type' => 'textbox', 'value' => $this->_view->dbSocket, 'title' => A::t('setup', 'Database Socket'), 'mandatoryStar' => true, 'htmlOptions' => array('maxLength' => '60', 'autocomplete' => 'off', 'placeholder' => '/tmp/mysql.sock'), 'validation' => array('required' => ($this->_view->dbConnectType == 'socket' ? true : false), 'type' => 'text'), 'disabled' => ($this->_view->dbConnectType == 'socket' ? false : true)],
293+
'dbHost' => ['type' => 'textbox', 'value' => $this->_view->dbHost, 'title' => A::t('setup', 'Database Host'), 'mandatoryStar' => true, 'htmlOptions' => array('maxLength' => '60', 'autocomplete' => 'off', 'placeholder' => 'e.g. localhost'), 'validation' => array('required' => ($this->_view->dbConnectType == 'host' ? true : false), 'type' => 'text'), 'disabled' => ($this->_view->dbConnectType == 'host' ? false : true)],
294+
'dbPort' => ['type' => 'textbox', 'value' => $this->_view->dbPort, 'title' => A::t('setup', 'Database Port'), 'mandatoryStar' => false, 'htmlOptions' => array('maxLength' => '10', 'autocomplete' => 'off', 'placeholder' => 'e.g. 3306', 'style' => 'width:80px'), 'validation' => array('required' => false, 'type' => 'integer'), 'disabled' => ($this->_view->dbConnectType == 'host' ? false : true)],
295+
'dbName' => ['type' => 'textbox', 'value' => $this->_view->dbName, 'title' => A::t('setup', 'Database Name'), 'mandatoryStar' => true, 'htmlOptions' => array('maxLength' => '30', 'autocomplete' => 'off'), 'validation' => array('required' => true, 'type' => 'text')],
296+
'dbUser' => ['type' => 'textbox', 'value' => $this->_view->dbUser, 'title' => A::t('setup', 'Database User'), 'mandatoryStar' => true, 'htmlOptions' => array('maxLength' => '30', 'autocomplete' => 'off'), 'validation' => array('required' => true, 'type' => 'text')],
297+
'dbPassword' => ['type' => 'password', 'value' => $this->_view->dbPassword, 'title' => A::t('setup', 'Database Password'), 'mandatoryStar' => false, 'htmlOptions' => array('maxLength' => '20', 'autocomplete' => 'off', 'id' => 'db_password'), 'validation' => array('required' => false, 'type' => 'text'), 'appendCode' => '<div for="db_password" class="toggle_password" data-field="db_password"></div>'],
298+
];
299299
$validationFields = array_merge($separatorGeneralFields, $separatorConenctionSettingsFields);
300300
$this->_view->formFields = array(
301301
'act' => array('type' => 'hidden', 'value' => 'send'),
@@ -307,16 +307,13 @@ public function databaseAction()
307307
if ($this->_cSession->get('step') < 2) {
308308
$this->redirect('setup/index');
309309
} elseif ($this->_cRequest->getPost('act') == 'send') {
310-
311-
$result = CWidget::create('CFormValidation', array(
312-
'fields' => $validationFields
313-
));
314-
315-
if ($result['error']) {
310+
$result = CWidget::create('CFormValidation', ['fields' => $validationFields]);
311+
312+
if ($result['error']) {
316313
$msg = $result['errorMessage'];
317314
$this->_view->errorField = $result['errorField'];
318315
} else {
319-
$model = new Setup(array(
316+
$model = new Setup([
320317
'dbDriver' => $this->_view->dbDriver,
321318
'dbConnectType' => $this->_view->dbConnectType,
322319
'dbSocket' => $this->_view->dbSocket,
@@ -325,7 +322,7 @@ public function databaseAction()
325322
'dbName' => $this->_view->dbName,
326323
'dbUser' => $this->_view->dbUser,
327324
'dbPassword' => $this->_view->dbPassword
328-
));
325+
]);
329326

330327
if ($model->getError()) {
331328
$this->_view->actionMessage = CWidget::create('CMessage', ['error', $model->getErrorMessage()]);
@@ -381,9 +378,9 @@ public function administratorAction()
381378

382379
$result = CWidget::create('CFormValidation', [
383380
'fields' => [
384-
'email' => array('title' => A::t('setup', 'Email'), 'validation' => array('required' => false, 'type' => 'email')),
385-
'username' => array('title' => A::t('setup', 'Username'), 'validation' => array('required' => true, 'type' => 'any', 'minLength' => 4, 'maxLength' => 32)),
386-
'password' => array('title' => A::t('setup', 'Password'), 'validation' => array('required' => true, 'type' => 'any', 'minLength' => 4, 'maxLength' => 25)),
381+
'email' => ['title' => A::t('setup', 'Email'), 'validation' => ['required' => false, 'type' => 'email']],
382+
'username' => ['title' => A::t('setup', 'Username'), 'validation' => ['required' => true, 'type' => 'any', 'minLength' => 4, 'maxLength' => 32]],
383+
'password' => ['title' => A::t('setup', 'Password'), 'validation' => ['required' => true, 'type' => 'any', 'minLength' => 4, 'maxLength' => 25]],
387384
],
388385
]);
389386

@@ -456,8 +453,8 @@ public function readyAction()
456453
]);
457454

458455
if ($model->getError()) {
459-
$this->_view->actionMessage = CWidget::create('CMessage', array('error', $model->getErrorMessage()));
460-
} else {
456+
$this->_view->actionMessage = CWidget::create('CMessage', ['error', $model->getErrorMessage()]);
457+
} else {
461458
if ($model->install($sqlDump)) {
462459
$modulesError = false;
463460
$modulesWarning = false;
@@ -481,7 +478,7 @@ public function readyAction()
481478
$model->doBeginTransaction();
482479
if (!$model->install($sqlDump, false)) {
483480
$modulesError = true;
484-
$this->_view->actionMessage = CWidget::create('CMessage', array('error', $model->getErrorMessage()));
481+
$this->_view->actionMessage = CWidget::create('CMessage', ['error', $model->getErrorMessage()]);
485482
} else {
486483
// Copy module files
487484
foreach ($xml->files->children() as $folder) {

demos/simple-blog/protected/controllers/PostsController.php

Lines changed: 53 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,24 @@ public function viewAction($postId = null)
6464
$msg = 'Wrong parameter passed! Please try again later.';
6565
$msgType = 'error';
6666
} else {
67-
$result = $postsModel->findAll(array(
68-
'limit' => (($this->_view->currentPage - 1) * $this->_view->pageSize) . ', ' . $this->_view->pageSize,
69-
'order' => 'post_datetime DESC',
70-
));
71-
}
67+
$result = $postsModel->findAll(
68+
[
69+
'limit' => (($this->_view->currentPage - 1) * $this->_view->pageSize).', '.$this->_view->pageSize,
70+
'order' => 'post_datetime DESC',
71+
]
72+
);
73+
}
7274
} else {
7375
$viewOnePost = true;
74-
$result = $postsModel->find(CConfig::get('db.prefix') . 'posts.id = :id', array(':id' => $postId));
75-
}
76-
$this->_view->viewOnePost = $viewOnePost;
76+
$result = $postsModel->find(CConfig::get('db.prefix').'posts.id = :id', [':id' => $postId]);
77+
}
78+
$this->_view->viewOnePost = $viewOnePost;
7779

7880
if (!$result) {
7981
$msg = (!empty($msg)) ? $msg : 'There are still no posts.';
8082
$msgType = (!empty($msgType)) ? $msgType : 'info';
81-
$this->_view->mainText = CWidget::create('CMessage', array($msgType, $msg, array('button' => false)));
82-
} else {
83+
$this->_view->mainText = CWidget::create('CMessage', [$msgType, $msg, ['button' => false]]);
84+
} else {
8385
$this->_view->mainText = '';
8486
if ($viewOnePost) {
8587
// meta tags specific for the post
@@ -123,28 +125,35 @@ public function indexAction($msg = '')
123125
$msg_text = 'Wrong parameter passed! Check post ID.';
124126
$msgType = 'error';
125127
}
126-
if (!empty($msg_text)) $this->_view->actionMessage = CWidget::create('CMessage', array($msgType, $msg_text, array('button' => true)));
127-
}
128-
129-
// prepare pagination vars
128+
if ( ! empty($msg_text)) {
129+
$this->_view->actionMessage = CWidget::create('CMessage', [$msgType, $msg_text, ['button' => true]]);
130+
}
131+
}
132+
133+
// prepare pagination vars
130134
$this->_view->targetPage = 'posts/index';
131135
$this->_view->currentPage = A::app()->getRequest()->getQuery('page', 'integer', 1);
132136
$this->_view->pageSize = 15;
133137
$this->_view->totalRecords = Posts::model()->count();
134138

135139
if (!$this->_view->currentPage) {
136-
$this->_view->actionMessage = CWidget::create('CMessage', array('error', 'Wrong parameter passed! Please try again later.', array('button' => true)));
137-
} else {
138-
$conditions = array(
139-
'limit' => (($this->_view->currentPage - 1) * $this->_view->pageSize) . ', ' . $this->_view->pageSize,
140-
'order' => 'post_datetime DESC',
140+
$this->_view->actionMessage = CWidget::create(
141+
'CMessage',
142+
['error', 'Wrong parameter passed! Please try again later.', ['button' => true]]
141143
);
144+
} else {
145+
$conditions = [
146+
'limit' => (($this->_view->currentPage - 1) * $this->_view->pageSize).', '.$this->_view->pageSize,
147+
'order' => 'post_datetime DESC',
148+
];
142149

143150
if (!true) {
144-
$this->_view->posts = Posts::model()->findAll(array(
145-
'limit' => (($this->_view->currentPage - 1) * $this->_view->pageSize) . ', ' . $this->_view->pageSize,
146-
'order' => 'post_datetime DESC',
147-
));
151+
$this->_view->posts = Posts::model()->findAll(
152+
[
153+
'limit' => (($this->_view->currentPage - 1) * $this->_view->pageSize).', '.$this->_view->pageSize,
154+
'order' => 'post_datetime DESC',
155+
]
156+
);
148157
}else{
149158
$posts = null;
150159
Posts::model()->chunk($conditions, [], 10, function ($records) use(&$posts){
@@ -216,11 +225,11 @@ public function insertAction()
216225
// Perform post add form validation
217226
$result = CWidget::create('CFormValidation', array(
218227
'fields' => array(
219-
'header' => array('title' => 'Header', 'validation' => array('required' => true, 'type' => 'any', 'maxLength' => 100)),
220-
'postText' => array('title' => 'Post Text', 'validation' => array('required' => true, 'type' => 'any', 'maxLength' => 4000)),
221-
'metaTagTitle' => array('title' => CHtml::encode('Tag <TITLE>'), 'validation' => array('required' => false, 'type' => 'any', 'maxLength' => 250)),
222-
'metaTagKeywords' => array('title' => CHtml::encode('Meta tag <KEYWORDS>'), 'validation' => array('required' => false, 'type' => 'any', 'maxLength' => 250)),
223-
'metaTagDescription' => array('title' => CHtml::encode('Meta tag <DESCRIPTION>'), 'validation' => array('required' => false, 'type' => 'any', 'maxLength' => 250)),
228+
'header' => ['title' => 'Header', 'validation' => ['required' => true, 'type' => 'any', 'maxLength' => 100]],
229+
'postText' => ['title' => 'Post Text', 'validation' => ['required' => true, 'type' => 'any', 'maxLength' => 4000]],
230+
'metaTagTitle' => ['title' => CHtml::encode('Tag <TITLE>'), 'validation' => ['required' => false, 'type' => 'any', 'maxLength' => 250]],
231+
'metaTagKeywords' => ['title' => CHtml::encode('Meta tag <KEYWORDS>'), 'validation' => ['required' => false, 'type' => 'any', 'maxLength' => 250]],
232+
'metaTagDescription' => ['title' => CHtml::encode('Meta tag <DESCRIPTION>'), 'validation' => ['required' => false, 'type' => 'any', 'maxLength' => 250]],
224233
),
225234
));
226235

@@ -271,8 +280,8 @@ public function insertAction()
271280
}
272281
}
273282
if (!empty($msg)) {
274-
$this->_view->actionMessage = CWidget::create('CMessage', array($msgType, $msg, array('button' => true)));
275-
$this->_view->render('posts/add');
283+
$this->_view->actionMessage = CWidget::create('CMessage', [$msgType, $msg, ['button' => true]]);
284+
$this->_view->render('posts/add');
276285
}
277286
} else {
278287
$this->redirect('posts/add');
@@ -333,11 +342,11 @@ public function updateAction()
333342
// perform post edit form validation
334343
$result = CWidget::create('CFormValidation', array(
335344
'fields' => array(
336-
'header' => array('title' => 'Header', 'validation' => array('required' => true, 'type' => 'any', 'maxLength' => 100)),
337-
'postText' => array('title' => 'Post Text', 'validation' => array('required' => true, 'type' => 'any', 'maxLength' => 4000)),
338-
'metaTagTitle' => array('title' => CHtml::encode('Tag <TITLE>'), 'validation' => array('required' => false, 'type' => 'any', 'maxLength' => 250)),
339-
'metaTagKeywords' => array('title' => CHtml::encode('Meta tag <KEYWORDS>'), 'validation' => array('required' => false, 'type' => 'any', 'maxLength' => 250)),
340-
'metaTagDescription' => array('title' => CHtml::encode('Meta tag <DESCRIPTION>'), 'validation' => array('required' => false, 'type' => 'any', 'maxLength' => 250)),
345+
'header' => ['title' => 'Header', 'validation' => ['required' => true, 'type' => 'any', 'maxLength' => 100]],
346+
'postText' => ['title' => 'Post Text', 'validation' => ['required' => true, 'type' => 'any', 'maxLength' => 4000]],
347+
'metaTagTitle' => ['title' => CHtml::encode('Tag <TITLE>'), 'validation' => ['required' => false, 'type' => 'any', 'maxLength' => 250]],
348+
'metaTagKeywords' => ['title' => CHtml::encode('Meta tag <KEYWORDS>'), 'validation' => ['required' => false, 'type' => 'any', 'maxLength' => 250]],
349+
'metaTagDescription' => ['title' => CHtml::encode('Meta tag <DESCRIPTION>'), 'validation' => ['required' => false, 'type' => 'any', 'maxLength' => 250]],
341350
),
342351
));
343352

@@ -363,8 +372,8 @@ public function updateAction()
363372
$post->metatag_title = $this->_view->metaTagTitle;
364373
$post->metatag_keywords = $this->_view->metaTagKeywords;
365374
$post->metatag_description = $this->_view->metaTagDescription;
366-
$post->setGuarded(array('author_id', 'post_datetime'));
367-
$saveResult = $posts->save($post);
375+
$post->setGuarded(['author_id', 'post_datetime']);
376+
$saveResult = $posts->save($post);
368377
} else {
369378
// Use model
370379
$posts = Posts::model()->findByPk($this->_view->postId);
@@ -389,9 +398,9 @@ public function updateAction()
389398
}
390399
}
391400
if (!empty($msg)) {
392-
$this->_view->actionMessage = CWidget::create('CMessage', array($msgType, $msg, array('button' => true)));
393-
}
394-
$this->_view->render('posts/edit');
401+
$this->_view->actionMessage = CWidget::create('CMessage', [$msgType, $msg, ['button' => true]]);
402+
}
403+
$this->_view->render('posts/edit');
395404
} else {
396405
$this->redirect('posts/index');
397406
}
@@ -420,10 +429,10 @@ public function deleteAction($postId)
420429
$msgType = 'error';
421430
}
422431
if (!empty($msg)) {
423-
$this->_view->actionMessage = CWidget::create('CMessage', array($msgType, $msg, array('button' => true)));
424-
}
425-
426-
$this->redirect('posts/index/msg/deleted');
432+
$this->_view->actionMessage = CWidget::create('CMessage', [$msgType, $msg, ['button' => true]]);
433+
}
434+
435+
$this->redirect('posts/index/msg/deleted');
427436
}
428437
}
429438

demos/simple-blog/protected/entities/PostEntity.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class PostEntity extends CRecordEntity
1717
/** @var */
1818
protected $_fillable = [];
1919
/** @var */
20-
protected $_guarded = array('post_datetime');
20+
protected $_guarded = ['post_datetime'];
2121

22-
/**
22+
/**
2323
* Class constructor
2424
* @param int $pkVal
2525
*/

0 commit comments

Comments
 (0)