<?php
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
class ListenerSuscriberSubscriber implements EventSubscriberInterface
{
private $sesssion;
public function __construct(SessionInterface $session)
{
$this->sesssion=$session;
}
public function onKernelRequest(RequestEvent $event)
{
$idiomas=array('es', 'us', 'de', 'fr', 'it', 'ru', 'nl');
$this->sesssion->set('idiomas',$idiomas);
if($idiom=$event->getRequest()->get('idioma')){
$this->sesssion->set('idiom',($idiom=='us')?'en':$idiom);
}elseif(!$this->sesssion->get('idiom')){
$this->sesssion->set('idiom','es');
}
/*
echo '<pre>';
print_r($event->getRequest()->get('idioma'));Exit;
*/
}
public static function getSubscribedEvents()
{
return [
'kernel.request' => 'onKernelRequest',
];
}
}