8000 [DX] Improve exception message when AbstractController::getParameter fails by curry684 · Pull Request #27443 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DX] Improve exception message when AbstractController::getParameter fails #27443

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

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove reference to upgrading DI as FrameworkBundle already required …
…^4.1
  • Loading branch information
curry684 committed May 31, 2018
commit 3dec31d959de2659d9f6dfcd18178aa35e766a2d
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,9 @@ public function setContainer(ContainerInterface $container)
protected function getParameter(string $name)
{
if (!$this->container->has('parameter_bag')) {
$message = 'The "parameter_bag" service could not be located. ';
if (!interface_exists(ContainerBagInterface::class)) {
$message .= 'Upgrade symfony/dependency-injection to at least 4.1.0 to have it injected automatically.';
} else {
$message .= 'Ensure that the controller is either set to be autoconfigured or wired manually to inject it.';
}

throw new ServiceNotFoundException('parameter_bag', null, null, array(), $message);
throw new ServiceNotFoundException('parameter_bag', null, null, array(),
'The "parameter_bag" service could not be located. Ensure that the controller is either set ' .
'to be autoconfigured or wired manually to inject it.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[...] to be autoconfigured or has the "container.service_subscriber" tag.?

should be on one single long line

Copy link
Member
@nicolas-grekas nicolas-grekas Jun 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sprintf('The "%s::getParameter()" method is missing a parameter bag to work properly. Did you forget to register your controller as a service subscriber? This can be fixed e.g. by using autoconfiguration or by manually wiring a "parameter_bag" in the service locator passed to the controller.', get_class($this))

(the name of the parameter is of no importance IMHO, but the controller class IS.)

}

return $this->container->get('parameter_bag')->get($name);
Expand Down
0