<?php
/**
* Created by PhpStorm.
* User: PMDiagne
* Date: 08/04/2020
* Time: 15:24
*/
namespace App\Event\Listener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use App\Utils\Constantes;
class BGLocaleSubscriber implements EventSubscriberInterface
{
private $defaultLocale;
public function __construct(string $defaultLocale = 'fr')
{
$this->defaultLocale = $defaultLocale;
}
public function onKernelRequest(RequestEvent $event)
{
$request = $event->getRequest();
if ($request->headers->has(Constantes::LOCALE_LANGUAGE)) {
$request->setLocale($request->headers->get(Constantes::LOCALE_LANGUAGE));
}
}
public static function getSubscribedEvents()
{
return [
// must be registered before (i.e. with a higher priority than) the default Locale listener
KernelEvents::REQUEST => [['onKernelRequest', 20]],
];
}
}