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
Getting the current locale in the service became a very hard task #5486
Comments
Hmmm, did you tried to turn off this services:
entity_locale_setter.listener:
class: Giftshop\FrontBundle\Listener\EntityLocaleSetter
arguments: [@request=]
tags:
- { name: doctrine.event_listener, event: postLoad } |
If you only need the locale I suggest passing the %locale% parameter instead of the Request service. |
@antoinegomez this will not give you the current locale but the default locale |
Yes i did, no effect. |
I think you come into the dark side of the dependency injection. Relaying on the request means moving to a narrower scope, because the request is created while the application is running. But as jedi ninjas, let's try to solve this. I would try to use a second event listener listening to # services.yml
services:
entity_locale_setter.listener:
class: Giftshop\FrontBundle\Listener\EntityLocaleSetter
tags:
- { name: doctrine.event_listener, event: postLoad }
kernel_request.listener:
class: Giftshop\FrontBundle\Listener\KernelRequestListener
arguments: [@entity_locale_setter.listener]
tags:
- { name: kernel.event_listener, method: onKernelRequest } <?php
// KernelRequestListener.php
namespace Giftshop\FrontBundle\Listener;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
class KernelRequestListener
{
private $entityLocaleSetter;
public function __construct(EntityLocaleSetter $entityLocaleSetter)
{
$this->entityLocaleSetter = $entityLocaleSetter;
}
public function onKernelRequest(GetResponseEvent $event)
{
$this->entityLocaleSetter->setRequest($event->getRequest());
}
} |
@lennerd Forgot to thank you, your solution solved my problem! |
I need to get current locale, before i've injected session, and got locale from there, now, after upgrade, I have to get it from request, so I do:
Obviously i get the scope widening error
Ok, i chnage it to scope:request and i get
Can someone tell me please, how to get the freaking locale? :D Why is it so hard, or I;m doing something wrong?
I'm injecting now the service container, but I don't like this dirty approach.
The text was updated successfully, but these errors were encountered: