You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
minor #25339 [DX][HttpKernel] Throw a sensible exception when controller has been removed (sroze)
This PR was merged into the 3.4 branch.
Discussion
----------
[DX][HttpKernel] Throw a sensible exception when controller has been removed
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #25335
| License | MIT
| Doc PR | ø
Following on #25201, we need to throw the same kind of sensible exception when the controller service is not found.
Commits
-------
458d63f Throw a sensible exception when controller has been removed
if ($this->container->has($controller) && method_exists($service = $this->container->get($controller), '__invoke')) {
74
-
// invokable controller in the "service" notation
75
-
return$service;
83
+
if (!method_exists($service, '__invoke')) {
84
+
thrownew \LogicException(sprintf('Controller "%s" cannot be called without a method name. Did you forget an "__invoke" method?', $controller));
76
85
}
77
86
78
-
thrownew \LogicException(sprintf('Unable to parse the controller name "%s".', $controller));
87
+
return$service;
79
88
}
80
89
81
90
/**
@@ -94,10 +103,19 @@ protected function instantiateController($class)
94
103
} catch (\TypeError$e) {
95
104
}
96
105
97
-
if ($this->containerinstanceof Container && isset($this->container->getRemovedIds()[$class])) {
98
-
thrownew \LogicException(sprintf('Controller "%s" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"?', $class), 0, $e);
if ($this->containerinstanceof Container && isset($this->container->getRemovedIds()[$controller])) {
118
+
thrownew \LogicException(sprintf('Controller "%s" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"?', $controller), 0, $previous);
* @expectedExceptionMessage Controller "app.my_controller" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"?
0 commit comments