Skip to content

Commit 51cdc3a

Browse files
committed
bug #48273 [HttpKernel] Fix message for unresovable arguments of invokable controllers (fancyweb)
This PR was merged into the 4.4 branch. Discussion ---------- [HttpKernel] Fix message for unresovable arguments of invokable controllers | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Before: ``` Could not resolve argument $logger of "app\controller\foocontroller()", maybe you ... ``` After: ``` Could not resolve argument $logger of "App\Controller\FooController::__invoke()", maybe you ... ``` Commits ------- a379c35 [HttpKernel] Fix message for unresovable arguments of invokable controllers
2 parents 0f670bb + a379c35 commit 51cdc3a

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ public function resolve(Request $request, ArgumentMetadata $argument): iterable
6969
}
7070

7171
if (!$this->container->has($controller)) {
72-
$i = strrpos($controller, ':');
73-
$controller = substr($controller, 0, $i).strtolower(substr($controller, $i));
72+
$controller = (false !== $i = strrpos($controller, ':'))
73+
? substr($controller, 0, $i).strtolower(substr($controller, $i))
74+
: $controller.'::__invoke';
7475
}
7576

7677
$what = sprintf('argument $%s of "%s()"', $argument->getName(), $controller);

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@ public function testControllerNameIsAnArray()
9898
$resolver->resolve($request, $argument);
9999
}
100100

101+
public function testInvokableController()
102+
{
103+
$this->expectException(RuntimeException::class);
104+
$this->expectExceptionMessage('Could not resolve argument $dummy of "App\Controller\Mine::__invoke()", maybe you forgot to register the controller as a service or missed tagging it with the "controller.service_arguments"?');
105+
$resolver = new NotTaggedControllerValueResolver(new ServiceLocator([]));
106+
$argument = new ArgumentMetadata('dummy', \stdClass::class, false, false, null);
107+
$request = $this->requestWithAttributes(['_controller' => 'App\Controller\Mine']);
108+
$this->assertTrue($resolver->supports($request, $argument));
109+
$resolver->resolve($request, $argument);
110+
}
111+
101112
private function requestWithAttributes(array $attributes)
102113
{
103114
$request = Request::create('/');

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy