From cc6f82769bd886ed2a0ddf745b1f1354cd62ecd0 Mon Sep 17 00:00:00 2001 From: nicoweb Date: Sat, 8 Sep 2018 14:42:42 +0200 Subject: [PATCH] [Controller][ServiceValueResolver] Making method access case insensitive --- .../ArgumentResolver/ServiceValueResolver.php | 9 +++++++++ .../ServiceValueResolverTest.php | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/ServiceValueResolver.php b/src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/ServiceValueResolver.php index 7bc195f233..3294ec862e 100644 --- a/src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/ServiceValueResolver.php +++ b/src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/ServiceValueResolver.php @@ -47,6 +47,10 @@ final class ServiceValueResolver implements ArgumentValueResolverInterface $controller = ltrim($controller, '\\'); } + if (!$this->container->has($controller) && false !== $i = strrpos($controller, ':')) { + $controller = substr($controller, 0, $i).strtolower(substr($controller, $i)); + } + return $this->container->has($controller) && $this->container->get($controller)->has($argument->getName()); } @@ -63,6 +67,11 @@ final class ServiceValueResolver implements ArgumentValueResolverInterface $controller = ltrim($controller, '\\'); } + if (!$this->container->has($controller)) { + $i = strrpos($controller, ':'); + $controller = substr($controller, 0, $i).strtolower(substr($controller, $i)); + } + yield $this->container->get($controller)->get($argument->getName()); } } diff --git a/src/Symfony/Component/HttpKernel/Tests/Controller/ArgumentResolver/ServiceValueResolverTest.php b/src/Symfony/Component/HttpKernel/Tests/Controller/ArgumentResolver/ServiceValueResolverTest.php index 7d34172ce3..f6a3689638 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Controller/ArgumentResolver/ServiceValueResolverTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Controller/ArgumentResolver/ServiceValueResolverTest.php @@ -66,6 +66,24 @@ class ServiceValueResolverTest extends TestCase $this->assertYieldEquals(array(new DummyService()), $resolver->resolve($request, $argument)); } + public function testExistingControllerWithMethodNameStartUppercase() + { + $resolver = new ServiceValueResolver(new ServiceLocator(array( + 'App\\Controller\\Mine::method' => function () { + return new ServiceLocator(array( + 'dummy' => function () { + return new DummyService(); + }, + )); + }, + ))); + $request = $this->requestWithAttributes(array('_controller' => 'App\\Controller\\Mine::Method')); + $argument = new ArgumentMetadata('dummy', DummyService::class, false, false, null); + + $this->assertTrue($resolver->supports($request, $argument)); + $this->assertYieldEquals(array(new DummyService()), $resolver->resolve($request, $argument)); + } + public function testControllerNameIsAnArray() { $resolver = new ServiceValueResolver(new ServiceLocator(array(