src/Controller/Public/HomeController.php line 19

  1. <?php
  2. namespace App\Controller\Public;
  3. use App\Entity\User;
  4. use App\Enum\Admin\RolesEnum;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. class HomeController extends AbstractController
  10. {
  11.     /**
  12.      * @param EntityManagerInterface $entityManager
  13.      * @return Response
  14.      */
  15.     #[Route('/'name'home')]
  16.     public function index(EntityManagerInterface $entityManager): Response
  17.     {
  18.         if ($this->isGranted(RolesEnum::ROLE_ADMIN)) {
  19.             return $this->redirectToRoute('app_admin');
  20.         }
  21.         if ($entityManager->getRepository(User::class)->count([])) {
  22.             return $this->redirectToRoute('app_login');
  23.         }
  24.         return $this->redirectToRoute('app_install');
  25.     }
  26. }