<?php
namespace Rawafed\CommonsBundle\Service;
use Doctrine\ORM\EntityManager;
use Symfony\Component\HttpKernel\Event\RequestEvent;
class LocaleListener
{
private $entity_manager;
private $locale;
public function __construct(EntityManager $entity_manager)
{
$this->entity_manager = $entity_manager;
}
public function onKernelRequest(RequestEvent $event)
{
$this->locale = $event->getRequest()->getLocale();
$filter = $this->entity_manager->getFilters()->enable('locale_filter');
$filter->setParameter('locale', $this->locale);
}
public function getLocale()
{
return $this->locale;
}
}