Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 11e5c56

Browse filesBrowse files
committed
[Controller][ServiceValueResolver] Making method access case insensitive
1 parent 5632dc7 commit 11e5c56
Copy full SHA for 11e5c56

File tree

Expand file treeCollapse file tree

2 files changed

+40
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+40
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/ServiceValueResolver.php
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public function supports(Request $request, ArgumentMetadata $argument)
4747
$controller = ltrim($controller, '\\');
4848
}
4949

50+
$controller = $this->normalizeMethod($controller);
51+
5052
return $this->container->has($controller) && $this->container->get($controller)->has($argument->getName());
5153
}
5254

@@ -63,6 +65,26 @@ public function resolve(Request $request, ArgumentMetadata $argument)
6365
$controller = ltrim($controller, '\\');
6466
}
6567

68+
$controller = $this->normalizeMethod($controller);
69+
6670
yield $this->container->get($controller)->get($argument->getName());
6771
}
72+
73+
private function normalizeMethod(string $controller): string
74+
{
75+
$controllerSplitted = preg_split('/::|:/', $controller);
76+
$methodKey = $this->getMethodKey($controllerSplitted);
77+
$controllerSplitted[$methodKey] = strtolower($controllerSplitted[$methodKey]);
78+
79+
return implode('::', $controllerSplitted);
80+
}
81+
82+
private function getMethodKey(array $controllerSplitted)
83+
{
84+
if (!\is_array($controllerSplitted) || empty($controllerSplitted)) {
85+
return null;
86+
}
87+
88+
return array_keys($controllerSplitted)[\count($controllerSplitted) - 1];
89+
}
6890
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/Controller/ArgumentResolver/ServiceValueResolverTest.php
+18Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.