<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
class DefaultController extends AbstractController
{
/**
* @Route("/")
* @param Request $request
* @return RedirectResponse
* @throws \InvalidArgumentException
*/
public function indexAction(Request $request)
{
return new RedirectResponse(
$this->generateUrl(
'_slug',
[
'url' => '',
'_locale' => $this->getLocale($request)
]
)
);
}
/**
* @param Request $request
* @return string
* @throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
*/
private function getLocale(Request $request)
{
$locales = array_filter(
explode('|', $this->getParameter('requiredlocales'))
);
return $request->getPreferredLanguage($locales);
}
}