<?php
namespace App\EventListener;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpFoundation\Response;
use Sylius\Component\Locale\Provider\LocaleProviderInterface;
use Sylius\Bundle\ShopBundle\Locale\LocaleSwitcherInterface;
final class LocaleResourceListener
{
private const DOMAIN_LOCALES = [
'www.papapiqueetmamancoud.com' => 'en_US',
'others' => 'fr_FR'
];
public function __construct(private LocaleProviderInterface $localeProvider,
private LocaleSwitcherInterface $localeSwitcher)
{
}
public function localeChecker(RequestEvent $event): Response {
if(array_key_exists($event->getRequest()->getHost(), self::DOMAIN_LOCALES)) {
return $this->localeSwitcher->handle($event->getRequest(), self::DOMAIN_LOCALES[$event->getRequest()->getHost()]);
}
return $this->localeSwitcher->handle($event->getRequest(), self::DOMAIN_LOCALES['others']);
}
}