diff --git a/framework/console/Controller.php b/framework/console/Controller.php index 6dc3575db2..fca10d7835 100644 --- a/framework/console/Controller.php +++ b/framework/console/Controller.php @@ -113,23 +113,23 @@ class Controller extends \yii\base\Controller $args = []; $missing = []; - foreach ($method->getParameters() as $i => $param) { + foreach ($method->getParameters() as $param) { if (($class = $param->getClass()) !== null) { $name = $param->getName(); $className = $class->getName(); if (Yii::$app->has($name) && ($obj = Yii::$app->get($name)) instanceof $className) { - $args[$i] = $obj; + $args[] = $obj; } else { - $args[$i] = Yii::$container->get($className); + $args[] = Yii::$container->get($className); } continue; } $value = array_shift($params); if (isset($value)) { - $args[$i] = $param->isArray() ? preg_split('/\s*,\s*/', $value) : $value; + $args[] = $param->isArray() ? preg_split('/\s*,\s*/', $value) : $value; } else { if ($param->isDefaultValueAvailable()) { - $args[$i] = $param->getDefaultValue(); + $args[] = $param->getDefaultValue(); } else { $missing[] = $param->getName(); } @@ -140,6 +140,10 @@ class Controller extends \yii\base\Controller throw new Exception(Yii::t('yii', 'Missing required arguments: {params}', ['params' => implode(', ', $missing)])); } + // #9823 + foreach ($params as $value) { + $args[] = $value; + } return $args; } diff --git a/tests/framework/console/ControllerTest.php b/tests/framework/console/ControllerTest.php index c988dd22af..fb11146b40 100644 --- a/tests/framework/console/ControllerTest.php +++ b/tests/framework/console/ControllerTest.php @@ -78,9 +78,18 @@ class ControllerTest extends TestCase $result = $controller->runAction('aksi6', $params); $this->assertEquals(['mdmunir', false, true], $result); + $params = ['arg1', 'arg2', 'arg3']; + $result = $controller->runAction('aksi8', $params); + $this->assertEquals($params, $result); + + $params = ['arg1', 'arg2', 'arg3']; + $result = $controller->runAction('aksi9', $params); + $this->assertEquals(['arg1', 'arg2', Yii::$app->quxApp, 'arg3'], $result); + $params = ['avaliable']; $message = Yii::t('yii', 'Missing required arguments: {params}', ['params' => implode(', ', ['missing'])]); $this->setExpectedException('yii\console\Exception', $message); $result = $controller->runAction('aksi7', $params); + } } diff --git a/tests/framework/console/FakeController.php b/tests/framework/console/FakeController.php index b12ef40bac..575d0e4089 100644 --- a/tests/framework/console/FakeController.php +++ b/tests/framework/console/FakeController.php @@ -53,4 +53,14 @@ class FakeController extends Controller { } + + public function actionAksi8($arg1, $arg2) + { + return func_get_args(); + } + + public function actionAksi9($arg1, $arg2, QuxInterface $quxApp) + { + return func_get_args(); + } }