diff --git a/framework/console/Controller.php b/framework/console/Controller.php index 6fc9a807cdb..d8d65630d9f 100644 --- a/framework/console/Controller.php +++ b/framework/console/Controller.php @@ -87,16 +87,16 @@ public function runAction($id, $params = []) if (!empty($params)) { // populate options here so that they are available in beforeAction(). $options = $this->options($id === '' ? $this->defaultAction : $id); - if (isset($params['alias'])) { + if (isset($params['_aliases'])) { $optionAliases = $this->optionAliases(); - foreach ($params['alias'] as $name => $value) { + foreach ($params['_aliases'] as $name => $value) { if (array_key_exists($name, $optionAliases)) { $params[$optionAliases[$name]] = $value; } else { throw new Exception(Yii::t('yii', 'Unknown alias: -{name}', ['name' => $name])); } } - unset($params['alias']); + unset($params['_aliases']); } foreach ($params as $name => $value) { if (in_array($name, $options, true)) { diff --git a/framework/console/Request.php b/framework/console/Request.php index 4882bd6e76f..8377d3a15d2 100644 --- a/framework/console/Request.php +++ b/framework/console/Request.php @@ -73,7 +73,7 @@ public function resolve() } } elseif (preg_match('/^-(\w+)(?:=(.*))?$/', $param, $matches)) { $name = $matches[1]; - $params['alias'][$name] = isset($matches[2]) ? $matches[2] : true; + $params['_aliases'][$name] = isset($matches[2]) ? $matches[2] : true; } else { $params[] = $param; } diff --git a/tests/framework/console/ControllerTest.php b/tests/framework/console/ControllerTest.php index 0cfc20e5d9d..2d0b5dd1129 100644 --- a/tests/framework/console/ControllerTest.php +++ b/tests/framework/console/ControllerTest.php @@ -35,12 +35,16 @@ public function testBindActionParams() $result = $controller->runAction('aksi2', $params); $this->assertEquals([['d426', 'mdmunir'], 'single'], $result); - $params = ['alias' => ['t' => 'test']]; + $params = ['_aliases' => ['t' => 'test']]; $result = $controller->runAction('aksi4', $params); $this->assertEquals('test', $result); - $params = ['alias' => ['ta' => 'from params,notdefault']]; - list($fromParam, $other) = $controller->runAction('aksi5', $params); + $params = ['_aliases' => ['a' => 'testAlias']]; + $result = $controller->runAction('aksi5', $params); + $this->assertEquals('testAlias', $result); + + $params = ['_aliases' => ['ta' => 'from params,notdefault']]; + list($fromParam, $other) = $controller->runAction('aksi6', $params); $this->assertEquals('from params', $fromParam); $this->assertEquals('notdefault', $other); diff --git a/tests/framework/console/FakeController.php b/tests/framework/console/FakeController.php index ebf59880df4..e515f8026c1 100644 --- a/tests/framework/console/FakeController.php +++ b/tests/framework/console/FakeController.php @@ -19,17 +19,24 @@ class FakeController extends Controller public $testArray = []; + public $alias; + public function options($actionID) { return array_merge(parent::options($actionID), [ 'test', - 'testArray' + 'testArray', + 'alias' ]); } public function optionAliases() { - return ['t' => 'test', 'ta' => 'testArray']; + return [ + 't' => 'test', + 'ta' => 'testArray', + 'a' => 'alias' + ]; } public function actionAksi1($fromParam, $other = 'default') @@ -52,6 +59,11 @@ public function actionAksi4() } public function actionAksi5() + { + return $this->alias; + } + + public function actionAksi6() { return $this->testArray; }