src\Security\AuthenticationEntryPoint.php line 28

  1. <?php
  2. namespace App\Security;
  3. use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException;
  4. use Symfony\Component\HttpFoundation\RedirectResponse;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\RequestStack;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  9. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  10. use Symfony\Component\Security\Core\Exception\AuthenticationException;
  11. use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
  12. class AuthenticationEntryPoint implements AuthenticationEntryPointInterface
  13. {
  14.     private $urlGenerator;
  15.     private $session;
  16.     private RequestStack $requestStack;
  17.     public function __construct(RequestStack $requestStackUrlGeneratorInterface $urlGenerator)
  18.     {
  19.         $this->urlGenerator $urlGenerator;
  20.         $this->requestStack $requestStack;
  21.         $this->session $this->getSession();
  22.         if (!$this->session->isStarted()) {
  23.             $this->session->start();
  24.         }
  25.     }
  26.     // Coonnexion requise pour acceder a une route, redirection ici
  27.     public function start(Request $requestAuthenticationException $authException null): Response
  28.     {
  29.         $this->session->getFlashBag()->add('actionPage''logFalse');
  30.         return new RedirectResponse('/');
  31.        // return new RedirectResponse($this->urlGenerator->generate('home'));
  32.     }
  33.     /**
  34.      * @throws SessionNotFoundException
  35.      */
  36.     private function getSession(): SessionInterface
  37.     {
  38.         return $this->requestStack->getSession();
  39.     }
  40. }