src/Controller/Main/LocaleController.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Main;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. /**
  6.  * Class LocaleController
  7.  * @package App\Controller\Main
  8.  */
  9. class LocaleController extends AbstractController
  10. {
  11.     const ROUTE_NAME 'locale_forward';
  12.     /**
  13.      * @param Request $request
  14.      * @param $url
  15.      * @return \Symfony\Component\HttpFoundation\RedirectResponse
  16.      */
  17.     public function forwardAction(Request $request$url)
  18.     {
  19.         $fullUrl sprintf(
  20.             '/%s/%s',
  21.             $request->getPreferredLanguage($this->getParameter('app.locales')),
  22.             $url
  23.         );
  24.         if ($this->get('router')->match($fullUrl)['_route'] != static::ROUTE_NAME) {
  25.             return $this->redirect($fullUrl);
  26.         }
  27.         throw $this->createNotFoundException();
  28.     }
  29. }