Revert DI injection via controller action method signature

reverts b7020065c and related commits.
reverts implementation of #9476

For reasons, see discussion https://github.com/yiisoft/yii2/issues/9476#issuecomment-179749039
This commit is contained in:
Carsten Brandt
2016-02-06 05:17:33 +01:00
parent e8a7a8a0f4
commit 42b8569846
12 changed files with 28 additions and 335 deletions

View File

@ -122,27 +122,16 @@ class Controller extends \yii\base\Controller
$method = new \ReflectionMethod($action, 'run');
}
$params = array_values($params);
$args = array_values($params);
$args = [];
$missing = [];
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[] = $obj;
} else {
$args[] = Yii::$container->get($className);
}
continue;
foreach ($method->getParameters() as $i => $param) {
if ($param->isArray() && isset($args[$i])) {
$args[$i] = preg_split('/\s*,\s*/', $args[$i]);
}
$value = array_shift($params);
if (isset($value)) {
$args[] = $param->isArray() ? preg_split('/\s*,\s*/', $value) : $value;
} else {
if (!isset($args[$i])) {
if ($param->isDefaultValueAvailable()) {
$args[] = $param->getDefaultValue();
$args[$i] = $param->getDefaultValue();
} else {
$missing[] = $param->getName();
}
@ -153,9 +142,6 @@ class Controller extends \yii\base\Controller
throw new Exception(Yii::t('yii', 'Missing required arguments: {params}', ['params' => implode(', ', $missing)]));
}
foreach ($params as $value) {
$args[] = $value;
}
return $args;
}
@ -418,9 +404,6 @@ class Controller extends \yii\base\Controller
/** @var \ReflectionParameter $reflection */
foreach ($method->getParameters() as $i => $reflection) {
$name = $reflection->getName();
if ($reflection->getClass() !== null) {
continue;
}
$tag = isset($params[$i]) ? $params[$i] : '';
if (preg_match('/^(\S+)\s+(\$\w+\s+)?(.*)/s', $tag, $matches)) {
$type = $matches[1];