<?php
namespace App\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class RouterListener implements EventSubscriberInterface
{
public function onGoToHome(RequestEvent $event): void
{
$request = $event->getRequest();
$parameters = (array) $request->attributes;
if('front_index_page' == $request->attributes->get('_route')) {
$routeparams = $request->attributes->get('_route_params');
$parameters['slug'] = $routeparams['slug'] == 'accueil' && $routeparams['_locale'] == 'de'? 'home': $routeparams['slug'];
}
$request->attributes->add($parameters);
unset($parameters['_route'], $parameters['_controller']);
$request->attributes->set('_route_params', $parameters);
}
/**
* @return mixed
*/
public static function getSubscribedEvents()
{
return [
KernelEvents::REQUEST => [['onGoToHome', 20]],
];
}
}