-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[4.1] The "parameter_bag" service is not available. #27436
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
Comments
The service doesn't have to be public as the AbstractController injects it in a private service locator. Does the problem occur again if you change it back to private now? You may have just into a caching issue. |
I already try that, if I put the service back to private the problem is not occurring. |
Can you share the output of If on a Windows system just run |
|
Ok that should all be fine. I cannot reproduce your issue however. I suspect in migrating from Would it be possible for you to create a reproducer? |
Trying to reproduce the issue, but not so simple.
|
Hi there, I create a reproducer here: https://github.com/emulienfou/symfony_issue_27436 The issue is when trying to access to the ParameterBag service, using However, if you are trying to do the same in a bundle, the ParameterBag service seems to be not available. You can try my reproducer by accessing directly to: http://issue_27436.symfony:9999 using my docker configuration to the App controller. It will display |
@emulienfou : The issue is that your bundle controller is not manually wired, nor autowired nor autoconfigured, so |
Although this indeed makes it not a bug I'm surprised |
That's because of symfony/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerResolver.php Lines 62 to 64 in 5937566
I don't remember what motivated this. |
Some explanations in https://github.com/symfony/symfony/pull/22157/files#r108040463 |
Hmm ok the reasoning there is not unfair, but the result seen in this issue is most unfortunate and I understand the confusion. @weaverryan @nicolas-grekas what's your opinion on this? |
My opinion is that the core issue is a bad configuration, it needs to be fixed there :) |
Yeah no contest that it's a configuration issue, just pointing 8000 out the DX sucks if you run into this situation. First of all we could actually detect DI being installed at runtime before throwing the current exception, and then fix both by changing the alternative exception to something like "The parameter_bag service could not be located. Ensure that the controller is either set to be autoconfigured or wired manually to inject it". |
Yep. PR welcome :) |
Thanks for that! Tried something like: services:
App\Issue27436Bundle\Controller\:
resource: ../../Controller
autowire: true But is not working ;( |
PR to improve the message is #27443, more reviews welcome. |
@emulienfou you should also add Autowire = try to automatically inject right services based on typehints In this case the autoconfigure is required to pick up the Also see https://symfony.com/blog/new-in-symfony-3-3-service-autoconfiguration |
After adding the I just update my reproducer code: https://github.com/emulienfou/symfony_issue_27436 |
That error has no lack of DX at all and explicitly tells you how to fix it. |
…getParameter fails (curry684) This PR was squashed before being merged into the 4.1 branch (closes #27443). Discussion ---------- [DX] Improve exception message when AbstractController::getParameter fails | Q | A | ------------- | --- | Branch? | 4.1 | Bug fix? | no (DX) | New feature? | no | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #27436 | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Improve exception message for situations where the `parameter_bag` is not present in `AbstractController`. Also fixed the exception to the correct type. Commits ------- a8f4128 [DX] Improve exception message when AbstractController::getParameter fails
…ainer in AbstractController instances (nicolas-grekas) This PR was merged into the 4.2-dev branch. Discussion ---------- [FrameworkBundle] Deprecate auto-injection of the container in AbstractController instances | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Should enhance DX by preventing situations like #27436. Commits ------- e2f344f [FrameworkBundle] Deprecate auto-injection of the container in AbstractController instances
Symfony version(s) affected: 4.1.0
Description
Since updated to Symfony 4.1, I switch to use
AbstractController
instead ofController
class, as suggested!However, I receive now the LogicExtension:
The "parameter_bag" service is not available. Try running "composer require dependency-injection:^4.1"
.It seems the the service
parameter_bag
is not public and cannot be acceded!Using the debug command:
php bin/console debug:container parameter_bag
How to reproduce
Possible Solution
In the file:
framework-bundle/Resources/config/services.xml
Change:
By:
To make the service has
public
seems to resolve the issue!The text was updated successfully, but these errors were encountered: