Skip to content

Commit

Permalink
Short array syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
samdark committed Oct 18, 2013
1 parent f4e3edb commit 1f6a823
Show file tree
Hide file tree
Showing 380 changed files with 4,808 additions and 5,058 deletions.
11 changes: 4 additions & 7 deletions apps/advanced/backend/config/AppAsset.php
Expand Up @@ -17,13 +17,10 @@ class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = array(
'css/site.css',
);
public $js = array(
);
public $depends = array(
public $css = ['css/site.css'];
public $js = [];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
);
];
}
39 changes: 19 additions & 20 deletions apps/advanced/backend/config/main.php
Expand Up @@ -8,35 +8,34 @@
require(__DIR__ . '/params-local.php')
);

return array(
return [
'id' => 'app-backend',
'basePath' => dirname(__DIR__),
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
'preload' => array('log'),
'preload' => ['log'],
'controllerNamespace' => 'backend\controllers',
'modules' => array(
),
'components' => array(
'request' => array(
'modules' => [],
'components' => [
'request' => [
'enableCsrfValidation' => true,
),
],
'db' => $params['components.db'],
'cache' => $params['components.cache'],
'user' => array(
'user' => [
'identityClass' => 'common\models\User',
),
'log' => array(
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => array(
array(
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => array('error', 'warning'),
),
),
),
'errorHandler' => array(
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
),
),
],
],
'params' => $params,
);
];
4 changes: 2 additions & 2 deletions apps/advanced/backend/config/params.php
@@ -1,4 +1,4 @@
<?php
return array(
return [
'adminEmail' => 'admin@example.com',
);
];
4 changes: 2 additions & 2 deletions apps/advanced/console/migrations/m130524_201442_init.php
Expand Up @@ -9,7 +9,7 @@ public function up()
// MySQL-specific table options. Adjust if you plan working with another DBMS
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';

$this->createTable('tbl_user', array(
$this->createTable('tbl_user', [
'id' => Schema::TYPE_PK,
'username' => Schema::TYPE_STRING.' NOT NULL',
'auth_key' => Schema::TYPE_STRING.'(32) NOT NULL',
Expand All @@ -21,7 +21,7 @@ public function up()
'status' => 'tinyint NOT NULL DEFAULT 10',
'create_time' => Schema::TYPE_INTEGER.' NOT NULL',
'update_time' => Schema::TYPE_INTEGER.' NOT NULL',
), $tableOptions);
], $tableOptions);
}

public function down()
Expand Down
4 changes: 2 additions & 2 deletions apps/advanced/environments/dev/backend/config/main-local.php
Expand Up @@ -4,8 +4,8 @@
//'debug',
],
'modules' => [
// 'debug' => array(
// 'debug' => [
// 'class' => 'yii\debug\Module',
// ),
// ],
],
];
4 changes: 2 additions & 2 deletions apps/advanced/environments/dev/frontend/config/main-local.php
Expand Up @@ -4,8 +4,8 @@
//'debug',
],
'modules' => [
// 'debug' => array(
// 'debug' => [
// 'class' => 'yii\debug\Module',
// ),
// ],
],
];
12 changes: 6 additions & 6 deletions apps/advanced/environments/index.php
Expand Up @@ -6,14 +6,14 @@
* format:
*
* ```php
* return array(
* 'environment name' => array(
* return [
* 'environment name' => [
* 'path' => 'directory storing the local files',
* 'writable' => array(
* 'writable' => [
* // list of directories that should be set writable
* ),
* ),
* );
* ],
* ],
* ];
* ```
*/
return [
Expand Down
12 changes: 6 additions & 6 deletions apps/benchmark/index.php
Expand Up @@ -4,15 +4,15 @@

require(__DIR__ . '/protected/vendor/yiisoft/yii2/yii/Yii.php');

$config = array(
$config = [
'id' => 'benchmark',
'basePath' => __DIR__ . '/protected',
'components' => array(
'urlManager' => array(
'components' => [
'urlManager' => [
'enablePrettyUrl' => true,
),
)
);
],
],
];

$application = new yii\web\Application($config);
$application->run();
4 changes: 2 additions & 2 deletions build/build
Expand Up @@ -13,9 +13,9 @@ defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));

require(__DIR__ . '/../framework/yii/Yii.php');

$application = new yii\console\Application(array(
$application = new yii\console\Application([
'id' => 'yii-build',
'basePath' => __DIR__,
'controllerNamespace' => 'yii\build\controllers',
));
]);
$application->run();
16 changes: 8 additions & 8 deletions build/controllers/ClassmapController.php
Expand Up @@ -32,7 +32,7 @@ public function actionCreate($root = null, $mapFile = null)
if ($mapFile === null) {
$mapFile = YII_PATH . '/classes.php';
}
$options = array(
$options = [
'filter' => function ($path) {
if (is_file($path)) {
$file = basename($path);
Expand All @@ -42,18 +42,18 @@ public function actionCreate($root = null, $mapFile = null)
}
return null;
},
'only' => array('.php'),
'except' => array(
'only' => ['.php'],
'except' => [
'Yii.php',
'BaseYii.php',
'/debug/',
'/console/',
'/test/',
'/gii/',
),
);
],
];
$files = FileHelper::findFiles($root, $options);
$map = array();
$map = [];
foreach ($files as $file) {
if (($pos = strpos($file, $root)) !== 0) {
die("Something wrong: $file\n");
Expand All @@ -76,9 +76,9 @@ public function actionCreate($root = null, $mapFile = null)
* @license http://www.yiiframework.com/license/
*/
return array(
return [
$map
);
];
EOD;
if (is_file($mapFile) && file_get_contents($mapFile) === $output) {
Expand Down
25 changes: 12 additions & 13 deletions build/controllers/PhpDocController.php
Expand Up @@ -44,7 +44,7 @@ public function actionProperty($root=null)
$root = YII_PATH;
}
$root = FileHelper::normalizePath($root);
$options = array(
$options = [
'filter' => function ($path) {
if (is_file($path)) {
$file = basename($path);
Expand All @@ -54,16 +54,16 @@ public function actionProperty($root=null)
}
return null;
},
'only' => array('.php'),
'except' => array(
'only' => ['.php'],
'except' => [
'BaseYii.php',
'Yii.php',
'/debug/views/',
'/requirements/',
'/gii/views/',
'/gii/generators/',
),
);
],
];
$files = FileHelper::findFiles($root, $options);
$nFilesTotal = 0;
$nFilesUpdated = 0;
Expand All @@ -89,7 +89,7 @@ public function actionProperty($root=null)

public function globalOptions()
{
return array_merge(parent::globalOptions(), array('updateFiles'));
return array_merge(parent::globalOptions(), ['updateFiles']);
}

protected function updateClassPropertyDocs($file, $className, $propertyDoc)
Expand Down Expand Up @@ -136,7 +136,7 @@ protected function updateClassPropertyDocs($file, $className, $propertyDoc)
$start = $ref->getStartLine() - 2;
$docStart = $start - count(explode("\n", $oldDoc)) + 1;

$newFileContent = array();
$newFileContent = [];
$n = count($fileContent);
for($i = 0; $i < $n; $i++) {
if ($i > $start || $i < $docStart) {
Expand Down Expand Up @@ -253,16 +253,15 @@ protected function generateClassPropertyDocs($fileName)
'[\s\n]{2,}public function [g|s]et(?<name>\w+)\(((?:,? ?\$\w+ ?= ?[^,]+)*|\$\w+(?:, ?\$\w+ ?= ?[^,]+)*)\)#',
$class['content']);
$acrs = array_merge($properties, $gets, $sets);
//print_r($acrs); continue;

$props = array();
$props = [];
foreach ($acrs as &$acr) {
$acr['name'] = lcfirst($acr['name']);
$acr['comment'] = trim(preg_replace('#(^|\n)\s+\*\s?#', '$1 * ', $acr['comment']));
$props[$acr['name']][$acr['kind']] = array(
$props[$acr['name']][$acr['kind']] = [
'type' => $acr['type'],
'comment' => $this->fixSentence($acr['comment']),
);
];
}

ksort($props);
Expand Down Expand Up @@ -299,12 +298,12 @@ protected function generateClassPropertyDocs($fileName)
$phpdoc .= " *\n";
}
}
return array($className, $phpdoc);
return [$className, $phpdoc];
}

protected function match($pattern, $subject)
{
$sets = array();
$sets = [];
preg_match_all($pattern . 'suU', $subject, $sets, PREG_SET_ORDER);
foreach ($sets as &$set)
foreach ($set as $i => $match)
Expand Down
16 changes: 8 additions & 8 deletions docs/api/base/Component.md
Expand Up @@ -25,8 +25,8 @@ In the above, an anonymous function is attached to the "update" event of the pos
the following types of event handlers:

- anonymous function: `function($event) { ... }`
- object method: `array($object, 'handleAdd')`
- static class method: `array('Page', 'handleAdd')`
- object method: `[$object, 'handleAdd']`
- static class method: `['Page', 'handleAdd']`
- global function: `'handleAdd'`

The signature of an event handler should be like the following:
Expand All @@ -41,9 +41,9 @@ You can also attach a handler to an event when configuring a component with a co
The syntax is like the following:

~~~
array(
[
'on add' => function($event) { ... }
)
]
~~~

where `on add` stands for attaching an event to the `add` event.
Expand All @@ -69,11 +69,11 @@ One can also attach a behavior to a component when configuring it with a configu
following:

~~~
array(
'as tree' => array(
[
'as tree' => [
'class' => 'Tree',
),
)
],
]
~~~

where `as tree` stands for attaching a behavior named `tree`, and the array will be passed to [[\Yii::createObject()]]
Expand Down
4 changes: 2 additions & 2 deletions docs/api/base/Object.md
Expand Up @@ -50,12 +50,12 @@ In order to ensure the above life cycles, if a child class of Object needs to ov
it should be done like the following:

~~~
public function __construct($param1, $param2, ..., $config = array())
public function __construct($param1, $param2, ..., $config = [])
{
...
parent::__construct($config);
}
~~~

That is, a `$config` parameter (defaults to `array()`) should be declared as the last parameter
That is, a `$config` parameter (defaults to `[]`) should be declared as the last parameter
of the constructor, and the parent implementation should be called at the end of the constructor.
8 changes: 4 additions & 4 deletions docs/api/db/ActiveRecord-find.md
Expand Up @@ -8,19 +8,19 @@ $customers = Customer::find()->all();
// find all active customers and order them by their age:
$customers = Customer::find()
->where(array('status' => 1))
->where(['status' => 1])
->orderBy('age')
->all();
// find a single customer whose primary key value is 10
$customer = Customer::find(10);
// the above is equivalent to:
$customer = Customer::find()->where(array('id' => 10))->one();
$customer = Customer::find()->where(['id' => 10])->one();
// find a single customer whose age is 30 and whose status is 1
$customer = Customer::find(array('age' => 30, 'status' => 1));
$customer = Customer::find(['age' => 30, 'status' => 1]);
// the above is equivalent to:
$customer = Customer::find()->where(array('age' => 30, 'status' => 1))->one();
$customer = Customer::find()->where(['age' => 30, 'status' => 1])->one();
~~~

4 comments on commit 1f6a823

@zinzinday
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, we must build a tool to do this, there are many places have not been replaced.

@samdark
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you could point these that would be great.

@cebe
Copy link
Member

@cebe cebe commented on 1f6a823 Oct 22, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do another replacement right now.

@cebe
Copy link
Member

@cebe cebe commented on 1f6a823 Oct 22, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a few in docs. 40d06e6
@zinzinday have you seen more? As far as I see we got them all. What you find when searching for array( is calls to is_array() and in_array() methods.

Please sign in to comment.