Controllers do not work in Symfony 5.0.4
AlexeyKosov opened this issue · 6 comments
The abstract PayumController uses $this->get('payum')
for accessing the service, but this way no longer works and throws an exception in Symfony 5.0.4:
Service "payum" not found: even though it exists in the app's container, the container inside "Payum\Bundle\PayumBundle\Controller\CaptureController" is a smaller service locator that only knows about the "doctrine", "form.factory", "http_kernel", "parameter_bag", "request_stack", "router", "security.authorization_checker", "security.csrf.token_manager", "security.token_storage", "serializer", "session" and "twig" services.
Try using dependency injection instead.
Obviously, $this->get()
should be replaced with dependency injection through a constructor.
When I'll find time I'll fix the issue. In the meantime you can solve this issue by adding something like this into your services.yaml
# config/services.yaml
services:
Payum\Bundle\PayumBundle\Controller\AuthorizeController:
calls:
- method: setContainer
arguments: ['@service_container']
Payum\Bundle\PayumBundle\Controller\CancelController:
calls:
- method: setContainer
arguments: ['@service_container']
Payum\Bundle\PayumBundle\Controller\CaptureController:
calls:
- method: setContainer
arguments: ['@service_container']
Payum\Bundle\PayumBundle\Controller\NotifyController:
calls:
- method: setContainer
arguments: ['@service_container']
Payum\Bundle\PayumBundle\Controller\PayoutController:
calls:
- method: setContainer
arguments: ['@service_container']
Payum\Bundle\PayumBundle\Controller\RefundController:
calls:
- method: setContainer
arguments: ['@service_container']
Payum\Bundle\PayumBundle\Controller\SyncController:
calls:
- method: setContainer
arguments: ['@service_container']
When I'll find time I'll fix the issue. In the meantime you can solve this issue by adding something like this into your services.yaml
# config/services.yaml services: Payum\Bundle\PayumBundle\Controller\AuthorizeController: calls: - method: setContainer arguments: ['@service_container'] Payum\Bundle\PayumBundle\Controller\CancelController: calls: - method: setContainer arguments: ['@service_container'] Payum\Bundle\PayumBundle\Controller\CaptureController: calls: - method: setContainer arguments: ['@service_container'] Payum\Bundle\PayumBundle\Controller\NotifyController: calls: - method: setContainer arguments: ['@service_container'] Payum\Bundle\PayumBundle\Controller\PayoutController: calls: - method: setContainer arguments: ['@service_container'] Payum\Bundle\PayumBundle\Controller\RefundController: calls: - method: setContainer arguments: ['@service_container'] Payum\Bundle\PayumBundle\Controller\SyncController: calls: - method: setContainer arguments: ['@service_container']
this doesn't work for me and I still get the error that "service 'payum' not found"
@Miinoo11 Please share more information about your error and make sure you're on latest version of payum/core
and payum/payum-bundle
@Miinoo11 Please share more information about your error and make sure you're on latest version of
payum/core
andpayum/payum-bundle
I'm getting the same Error like the OP mentioned:
Service "payum" not found: even though it exists in the app's container, the container inside "Payum\Bundle\PayumBundle\Controller\CaptureController" is a smaller service locator that only knows about the "doctrine", "form.factory", "http_kernel", "parameter_bag", "request_stack", "router", "security.authorization_checker", "security.csrf.token_manager", "security.token_storage", "serializer", "session" and "twig" services.
Try using dependency injection instead.
Can't test it, but it should work https://github.com/Payum/PayumBundle/blob/master/Controller/PayumController.php#L22
Are you sure you have payum/payum-bundle 2.4.2
?
Tthis code was modified since that PR was merged, so maybe somebody broke it.