src/FlexApp/EventSubscriber/LogoutSubscriber.php line 18

Open in your IDE?
  1. <?php
  2. namespace FlexApp\EventSubscriber;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use FlexApp\Service\CurrentUserProvider;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpFoundation\Cookie;
  7. use Symfony\Component\Security\Http\Event\LogoutEvent;
  8. class LogoutSubscriber implements EventSubscriberInterface
  9. {
  10.     /** @required */
  11.     public CurrentUserProvider $currentUserProvider;
  12.     /** @required */
  13.     public EntityManagerInterface $entityManager;
  14.     public function onLogoutEvent(LogoutEvent $event)
  15.     {
  16.         $response $event->getResponse();
  17.         $token hash('sha256'uniqid());
  18.         $cookie = new Cookie('token'$tokentime() + 94608000'/');
  19.         $_SESSION['token'] = $token;
  20.         $response->headers->setCookie($cookie);
  21.     }
  22.     public static function getSubscribedEvents()
  23.     {
  24.         return [
  25.             LogoutEvent::class => 'onLogoutEvent',
  26.         ];
  27.     }
  28. }