Skip to content

Commit

Permalink
WIP yiisoft#10840: rename key 'alias' to '_aliases'
Browse files Browse the repository at this point in the history
  • Loading branch information
pana1990 committed Feb 27, 2016
1 parent ac73aee commit 1ce21cd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
6 changes: 3 additions & 3 deletions framework/console/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion framework/console/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 7 additions & 3 deletions tests/framework/console/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
16 changes: 14 additions & 2 deletions tests/framework/console/FakeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -52,6 +59,11 @@ public function actionAksi4()
}

public function actionAksi5()
{
return $this->alias;
}

public function actionAksi6()
{
return $this->testArray;
}
Expand Down

0 comments on commit 1ce21cd

Please sign in to comment.