Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be05bbf

Browse files
bug #28404 [Controller][ServiceValueResolver] Making method access case insensitive (nicoweb)
This PR was merged into the 3.4 branch. Discussion ---------- [Controller][ServiceValueResolver] Making method access case insensitive | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #28254 | License | MIT | Doc PR | - Fix #28254 by making the method access insensitive in `ServiceValueResolver`. Commits ------- cc6f827 [Controller][ServiceValueResolver] Making method access case insensitive
2 parents 49992c5 + cc6f827 commit be05bbf

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/ServiceValueResolver.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public function supports(Request $request, ArgumentMetadata $argument)
4747
$controller = ltrim($controller, '\\');
4848
}
4949

50+
if (!$this->container->has($controller) && false !== $i = strrpos($controller, ':')) {
51+
$controller = substr($controller, 0, $i).strtolower(substr($controller, $i));
52+
}
53+
5054
return $this->container->has($controller) && $this->container->get($controller)->has($argument->getName());
5155
}
5256

@@ -63,6 +67,11 @@ public function resolve(Request $request, ArgumentMetadata $argument)
6367
$controller = ltrim($controller, '\\');
6468
}
6569

70+
if (!$this->container->has($controller)) {
71+
$i = strrpos($controller, ':');
72+
$controller = substr($controller, 0, $i).strtolower(substr($controller, $i));
73+
}
74+
6675
yield $this->container->get($controller)->get($argument->getName());
6776
}
6877
}

src/Symfony/Component/HttpKernel/Tests/Controller/ArgumentResolver/ServiceValueResolverTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,24 @@ public function testExistingControllerWithATrailingBackSlash()
6666
$this->assertYieldEquals(array(new DummyService()), $resolver->resolve($request, $argument));
6767
}
6868

69+
public function testExistingControllerWithMethodNameStartUppercase()
70+
{
71+
$resolver = new ServiceValueResolver(new ServiceLocator(array(
72+
'App\\Controller\\Mine::method' => function () {
73+
return new ServiceLocator(array(
74+
'dummy' => function () {
75+
return new DummyService();
76+
},
77+
));
78+
},
79+
)));
80+
$request = $this->requestWithAttributes(array('_controller' => 'App\\Controller\\Mine::Method'));
81+
$argument = new ArgumentMetadata('dummy', DummyService::class, false, false, null);
82+
83+
$this->assertTrue($resolver->supports($request, $argument));
84+
$this->assertYieldEquals(array(new DummyService()), $resolver->resolve($request, $argument));
85+
}
86+
6987
public function testControllerNameIsAnArray()
7088
{
7189
$resolver = new ServiceValueResolver(new ServiceLocator(array(

0 commit comments

Comments
 (0)