src/Controller/HomeController.php line 55

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use App\Services\SessionService;
  8. use Symfony\Contracts\Translation\TranslatorInterface;
  9. class HomeController extends AbstractController
  10. {
  11.     private SessionService $sessionService;
  12.     public function __construct(SessionService $sessionService)
  13.     {
  14.         $this->sessionService $sessionService;
  15.     }
  16.     public function indexNoLocale(Request $request): Response
  17.     {
  18.         $language substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 02);
  19.         if ($request->get('lang')) {
  20.             $language $request->get('lang');
  21.         }
  22.         if ($language != 'fr' && $language != 'en') {
  23.             $language 'en';
  24.         }
  25.         return $this->redirectToRoute('root', ['_locale' => $language]);
  26.     }
  27.     public function oldUrlInterceptor(Request $request)
  28.     {
  29.         $language substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 02);
  30.         if ($request->get('lang')) {
  31.             $language $request->get('lang');
  32.         }
  33.         if ($language != 'fr' && $language != 'en') {
  34.             $language 'en';
  35.         }
  36.         $redirectUrl $this->generateUrl('root', ['_locale' => $language]);
  37.         return $this->redirect($redirectUrl);
  38.     }
  39.     #[Route('/'name'root'methods: ["GET"])]
  40.     public function index(Request $request): Response
  41.     {
  42.         return $this->redirectToRoute('app_login');
  43.     }
  44.     #[Route('/overview'name'overview'methods: ["GET"])]
  45.     public function overview(Request $request,TranslatorInterface $translator): Response
  46.     {
  47.         $data $this->sessionService->_getBaseParameters();
  48.         $session $request->getSession();
  49.         if ($session->get('code')) {
  50.             return $this->redirectToRoute('home');
  51.         }
  52.         $data['title'] = $translator->trans('pages.overview.title');
  53.         return $this->render('BasePages/overview.twig'$data);
  54.     }
  55.     #[Route('/questions'name'questions'methods: ["GET"])]
  56.     public function questions(Request $request,TranslatorInterface $translator): Response
  57.     {
  58.         $data $this->sessionService->_getBaseParameters();
  59.         $data['title'] = $translator->trans('pages.questions.title');
  60.         return $this->render('BasePages/questions.twig'$data);
  61.     }
  62. }