src/Controller/Base/BaseController.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Base;
  3. use App\Controller\AbstractController;
  4. use App\Domain\Application\Entity\Task;
  5. use App\Domain\User\Entity\User;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. use Symfony\Component\HttpFoundation\RedirectResponse;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
  10. class BaseController extends AbstractController
  11. {
  12.     #[Route('/'name'home')]
  13.     public function home(): RedirectResponse
  14.     {
  15.         return $this->redirectToRoute('admin');
  16.     }
  17.     #[Route('/admin-redirect'name'admin'options: ['expose' => true])]
  18.     public function admin(): RedirectResponse
  19.     {
  20.         if ($this->isGranted(User::ROLE_ADMIN)) {
  21.             return $this->redirectToRoute('admin_game_index');
  22.         } elseif ($this->isGranted(User::ROLE_CLIENT)) {
  23.             return $this->redirectToRoute('client_calendar_index');
  24.         } elseif ($this->isGranted(User::ROLE_USER)) {
  25.             throw $this->createAccessDeniedException("Vous n'avez pas le ROLE_ADMIN");
  26.         } else {
  27.             return $this->redirectToRoute('app_login');
  28.         }
  29.     }
  30.     #[Route('/check-task/{id}'name'check_task'options: ['expose' => true])]
  31.     public function checkTask(Task $taskNormalizerInterface $normalizer): JsonResponse
  32.     {
  33.         return $this->json(['task' => $normalizer->normalize($task)]);
  34.     }
  35. }