8000 [Controller][ServiceValueResolver] Making method access case insensitive by nicoweb · Pull Request #28404 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Controller][ServiceValueResolver] Making method access case insensitive #28404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Controller][ServiceValueResolver] Making method access case insensitive
  • Loading branch information
nicoweb committed Sep 8, 2018
commit cc6f82769bd886ed2a0ddf745b1f1354cd62ecd0
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public function supports(Request $request, ArgumentMetadata $argument)
$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());
}

Expand All @@ -63,6 +67,11 @@ public function resolve(Request $request, ArgumentMetadata $argument)
$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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ public function testExistingControllerWithATrailingBackSlash()
$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(
Expand Down
0