src/Controller/DefaultController.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\RedirectResponse;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\HttpFoundation\Request;
  7. class DefaultController extends AbstractController
  8. {
  9.         /**
  10.      * @Route("/")
  11.      * @param Request $request
  12.      * @return RedirectResponse
  13.      * @throws \InvalidArgumentException
  14.      */
  15.     public function indexAction(Request $request)
  16.     {
  17.         return new RedirectResponse(
  18.             $this->generateUrl(
  19.                 '_slug',
  20.                 [
  21.                     'url'       => '',
  22.                     '_locale'   => $this->getLocale($request)
  23.                 ]
  24.             )
  25.         );
  26.     }
  27.     /**
  28.      * @param Request $request
  29.      * @return string
  30.      * @throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
  31.      */
  32.     private function getLocale(Request $request)
  33.     {
  34.         $locales array_filter(
  35.             explode('|'$this->getParameter('requiredlocales'))
  36.         );
  37.         return $request->getPreferredLanguage($locales);
  38.     }
  39. }