From ea60fba0aea97beade39c108568cb27a5b70aba7 Mon Sep 17 00:00:00 2001 From: Bizley Date: Mon, 6 Sep 2021 20:16:14 +0200 Subject: [PATCH] Fix yii\base\Controller::bindInjectedParams() to not throw error when argument of `ReflectionUnionType` type is passed (#18869) --- framework/CHANGELOG.md | 1 + framework/base/Controller.php | 4 ++++ framework/console/Controller.php | 2 +- framework/web/Controller.php | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 7a0ccc3d20..e2e56095c6 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -14,6 +14,7 @@ Yii Framework 2 Change Log - Enh #18783: Add `XmlResponseFormatter::$objectTagToLowercase` option to lowercase object tags (WinterSilence, samdark) - Bug #18845: Fix duplicating `id` in `MigrateController::addDefaultPrimaryKey()` (WinterSilence, samdark) - Bug #17119: Fix `yii\caching\Cache::multiSet()` to use `yii\caching\Cache::$defaultDuration` when no duration is passed (OscarBarrett) +- Bug #18842: Fix `yii\base\Controller::bindInjectedParams()` to not throw error when argument of `ReflectionUnionType` type is passed (bizley) 2.0.43 August 09, 2021 diff --git a/framework/base/Controller.php b/framework/base/Controller.php index 0c79060cef..8ea901c37b 100644 --- a/framework/base/Controller.php +++ b/framework/base/Controller.php @@ -563,6 +563,10 @@ class Controller extends Component implements ViewContextInterface */ final protected function bindInjectedParams(\ReflectionType $type, $name, &$args, &$requestedParams) { + if (!$type instanceof \ReflectionNamedType || $type->isBuiltin()) { + return; + } + // Since it is not a builtin type it must be DI injection. $typeName = $type->getName(); if (($component = $this->module->get($name, false)) instanceof $typeName) { diff --git a/framework/console/Controller.php b/framework/console/Controller.php index fa0555386c..885d774e1b 100644 --- a/framework/console/Controller.php +++ b/framework/console/Controller.php @@ -226,7 +226,7 @@ class Controller extends \yii\base\Controller } $args[] = $actionParams[$key] = $params[$key]; unset($params[$key]); - } elseif (PHP_VERSION_ID >= 70100 && ($type = $param->getType()) !== null && !$type->isBuiltin()) { + } elseif (PHP_VERSION_ID >= 70100 && ($type = $param->getType()) !== null) { try { $this->bindInjectedParams($type, $name, $args, $requestedParams); } catch (\yii\base\Exception $e) { diff --git a/framework/web/Controller.php b/framework/web/Controller.php index b52cf80c9e..5eac7ee534 100644 --- a/framework/web/Controller.php +++ b/framework/web/Controller.php @@ -177,7 +177,7 @@ class Controller extends \yii\base\Controller } $args[] = $actionParams[$name] = $params[$name]; unset($params[$name]); - } elseif (PHP_VERSION_ID >= 70100 && ($type = $param->getType()) !== null && !$type->isBuiltin()) { + } elseif (PHP_VERSION_ID >= 70100 && ($type = $param->getType()) !== null) { try { $this->bindInjectedParams($type, $name, $args, $requestedParams); } catch (HttpException $e) {