From ffc24b028fdc08ccb55e072394618a3ffe6fbb67 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 24 Nov 2021 09:45:16 +0100 Subject: [PATCH 1/7] Bump Symfony version to 4.4.36 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 3f5a3314ab..398f4c102c 100644 --- a/Kernel.php +++ b/Kernel.php @@ -76,12 +76,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '4.4.35'; - public const VERSION_ID = 40435; + public const VERSION = '4.4.36-DEV'; + public const VERSION_ID = 40436; public const MAJOR_VERSION = 4; public const MINOR_VERSION = 4; - public const RELEASE_VERSION = 35; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 36; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '11/2022'; public const END_OF_LIFE = '11/2023'; From 4f0521c5411cc07c2a1ce860e979be8636496086 Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Thu, 25 Nov 2021 13:05:50 +0100 Subject: [PATCH 2/7] Fix redundant type casts --- DataCollector/RequestDataCollector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DataCollector/RequestDataCollector.php b/DataCollector/RequestDataCollector.php index 2a3f6ce514..1fb226d13c 100644 --- a/DataCollector/RequestDataCollector.php +++ b/DataCollector/RequestDataCollector.php @@ -150,7 +150,7 @@ public function collect(Request $request, Response $response/*, \Throwable $exce 'method' => $request->getMethod(), 'controller' => $this->parseController($request->attributes->get('_controller')), 'status_code' => $statusCode, - 'status_text' => Response::$statusTexts[(int) $statusCode], + 'status_text' => Response::$statusTexts[$statusCode], ]), 0, '/', null, $request->isSecure(), true, false, 'lax' )); From eed35d5b55ed04d79d20cde17bc8455247464aca Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 16 Dec 2021 22:17:20 +0100 Subject: [PATCH 3/7] CS fixes --- Controller/ControllerResolver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Controller/ControllerResolver.php b/Controller/ControllerResolver.php index c3df8f9571..7b8deeff1b 100644 --- a/Controller/ControllerResolver.php +++ b/Controller/ControllerResolver.php @@ -47,7 +47,7 @@ public function getController(Request $request) if (isset($controller[0]) && \is_string($controller[0]) && isset($controller[1])) { try { $controller[0] = $this->instantiateController($controller[0]); - } catch (\Error | \LogicException $e) { + } catch (\Error|\LogicException $e) { try { // We cannot just check is_callable but have to use reflection because a non-static method // can still be called statically in PHP but we don't want that. This is deprecated in PHP 7, so we @@ -120,7 +120,7 @@ protected function createController($controller) try { $controller = [$this->instantiateController($class), $method]; - } catch (\Error | \LogicException $e) { + } catch (\Error|\LogicException $e) { try { if ((new \ReflectionMethod($class, $method))->isStatic()) { return $class.'::'.$method; From f2c0df0cbddbd6657dd7a5d89cb8ddc5d376c821 Mon Sep 17 00:00:00 2001 From: Maxime Steinhausser Date: Tue, 28 Dec 2021 14:37:08 +0100 Subject: [PATCH 4/7] [HttpKernel] Do not attempt to register enum arguments in controller service locator --- ...RegisterControllerArgumentLocatorsPass.php | 5 ++++ ...sterControllerArgumentLocatorsPassTest.php | 27 +++++++++++++++++++ Tests/Fixtures/Suit.php | 20 ++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 Tests/Fixtures/Suit.php diff --git a/DependencyInjection/RegisterControllerArgumentLocatorsPass.php b/DependencyInjection/RegisterControllerArgumentLocatorsPass.php index cf4ab60284..eef09fa822 100644 --- a/DependencyInjection/RegisterControllerArgumentLocatorsPass.php +++ b/DependencyInjection/RegisterControllerArgumentLocatorsPass.php @@ -127,6 +127,11 @@ public function process(ContainerBuilder $container) $type = ltrim($target = (string) ProxyHelper::getTypeHint($r, $p), '\\'); $invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE; + if (is_subclass_of($type, \UnitEnum::class, true)) { + // do not attempt to register enum typed arguments + continue; + } + if (isset($arguments[$r->name][$p->name])) { $target = $arguments[$r->name][$p->name]; if ('?' !== $target[0]) { diff --git a/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php b/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php index 5a0964f6c2..0207703d94 100644 --- a/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php +++ b/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php @@ -23,6 +23,7 @@ use Symfony\Component\DependencyInjection\ServiceLocator; use Symfony\Component\DependencyInjection\TypedReference; use Symfony\Component\HttpKernel\DependencyInjection\RegisterControllerArgumentLocatorsPass; +use Symfony\Component\HttpKernel\Tests\Fixtures\Suit; class RegisterControllerArgumentLocatorsPassTest extends TestCase { @@ -369,6 +370,25 @@ public function testNotTaggedControllerServiceReceivesLocatorArgument() $this->assertInstanceOf(Reference::class, $locatorArgument); } + + /** + * @requires PHP 8.1 + */ + public function testEnumArgumentIsIgnored() + { + $container = new ContainerBuilder(); + $resolver = $container->register('argument_resolver.service')->addArgument([]); + + $container->register('foo', NonNullableEnumArgumentWithDefaultController::class) + ->addTag('controller.service_arguments') + ; + + $pass = new RegisterControllerArgumentLocatorsPass(); + $pass->process($container); + + $locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0); + $this->assertEmpty(array_keys($locator), 'enum typed argument is ignored'); + } } class RegisterTestController @@ -430,3 +450,10 @@ public function fooAction(string $someArg) { } } + +class NonNullableEnumArgumentWithDefaultController +{ + public function fooAction(Suit $suit = Suit::Spades) + { + } +} diff --git a/Tests/Fixtures/Suit.php b/Tests/Fixtures/Suit.php new file mode 100644 index 0000000000..5d9623b225 --- /dev/null +++ b/Tests/Fixtures/Suit.php @@ -0,0 +1,20 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpKernel\Tests\Fixtures; + +enum Suit: string +{ + case Hearts = 'H'; + case Diamonds = 'D'; + case Clubs = 'C'; + case Spades = 'S'; +} From 1f0c4e18c39b406754e3764b065e9717bdb9eafa Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 28 Dec 2021 15:43:46 +0100 Subject: [PATCH 5/7] cs fix --- DependencyInjection/RegisterControllerArgumentLocatorsPass.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DependencyInjection/RegisterControllerArgumentLocatorsPass.php b/DependencyInjection/RegisterControllerArgumentLocatorsPass.php index eef09fa822..daba473151 100644 --- a/DependencyInjection/RegisterControllerArgumentLocatorsPass.php +++ b/DependencyInjection/RegisterControllerArgumentLocatorsPass.php @@ -127,7 +127,7 @@ public function process(ContainerBuilder $container) $type = ltrim($target = (string) ProxyHelper::getTypeHint($r, $p), '\\'); $invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE; - if (is_subclass_of($type, \UnitEnum::class, true)) { + if (is_subclass_of($type, \UnitEnum::class)) { // do not attempt to register enum typed arguments continue; } From c528c20c043cc514c5d078652afb26949d352713 Mon Sep 17 00:00:00 2001 From: Maxime Steinhausser Date: Wed, 29 Dec 2021 10:49:04 +0100 Subject: [PATCH 6/7] [DependencyInjection][HttpKernel] Fix enum typed bindings --- .../RegisterControllerArgumentLocatorsPass.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/DependencyInjection/RegisterControllerArgumentLocatorsPass.php b/DependencyInjection/RegisterControllerArgumentLocatorsPass.php index daba473151..871e3807c6 100644 --- a/DependencyInjection/RegisterControllerArgumentLocatorsPass.php +++ b/DependencyInjection/RegisterControllerArgumentLocatorsPass.php @@ -127,11 +127,6 @@ public function process(ContainerBuilder $container) $type = ltrim($target = (string) ProxyHelper::getTypeHint($r, $p), '\\'); $invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE; - if (is_subclass_of($type, \UnitEnum::class)) { - // do not attempt to register enum typed arguments - continue; - } - if (isset($arguments[$r->name][$p->name])) { $target = $arguments[$r->name][$p->name]; if ('?' !== $target[0]) { @@ -156,6 +151,9 @@ public function process(ContainerBuilder $container) $args[$p->name] = $bindingValue; } + continue; + } elseif (is_subclass_of($type, \UnitEnum::class)) { + // do not attempt to register enum typed arguments if not already present in bindings continue; } elseif (!$type || !$autowire || '\\' !== $target[0]) { continue; From dfb65dcad12ef433d45ad1c97f632cd52c7faa68 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 29 Dec 2021 13:48:41 +0100 Subject: [PATCH 7/7] Update VERSION for 4.4.36 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 398f4c102c..021f6c8cfd 100644 --- a/Kernel.php +++ b/Kernel.php @@ -76,12 +76,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '4.4.36-DEV'; + public const VERSION = '4.4.36'; public const VERSION_ID = 40436; public const MAJOR_VERSION = 4; public const MINOR_VERSION = 4; public const RELEASE_VERSION = 36; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '11/2022'; public const END_OF_LIFE = '11/2023';