src/Controller/BaseController.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Services\GrantedService;
  4. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\HttpKernel\Event\RequestEvent;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Component\Security\Core\Security;
  10. #[Route('/'name'app_base')]
  11. class BaseController extends AbstractController
  12. {
  13.     public function __construct(Security $security)
  14.     {
  15.         $this->security $security;
  16.         $this->twigData = [
  17.             'user' => $security->getUser(),
  18.         ];
  19.     }
  20.     #[Route('/'name'_index')]
  21.     public function index(): Response
  22.     {
  23.         if($this->security->getUser() != false){
  24.             if($this->isGranted('ROLE_ADMIN')){
  25.                 return $this->redirectToRoute('app_home_index');
  26.             }elseif($this->isGranted('ROLE_CONTENT_MANAGER')){
  27.                 return $this->redirectToRoute('app_home_index');
  28.             }else{
  29.                 return $this->redirectToRoute('app_dam_index');
  30.             }
  31.         }else{
  32.             return $this->redirectToRoute('app_login');
  33.         }
  34.     }
  35.     public function onKernelRequest(RequestEvent $event)
  36.     {
  37.         $request $event->getRequest();
  38.         // some logic to determine the $locale
  39.         $request->setLocale('fr');
  40.     }
  41. }