<?php
namespace App\Controller\Main;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
/**
* Class LocaleController
* @package App\Controller\Main
*/
class LocaleController extends AbstractController
{
const ROUTE_NAME = 'locale_forward';
/**
* @param Request $request
* @param $url
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function forwardAction(Request $request, $url)
{
$fullUrl = sprintf(
'/%s/%s',
$request->getPreferredLanguage($this->getParameter('app.locales')),
$url
);
if ($this->get('router')->match($fullUrl)['_route'] != static::ROUTE_NAME) {
return $this->redirect($fullUrl);
}
throw $this->createNotFoundException();
}
}