src/EventSubscriber/LogoutSubscriber.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Entity\TextLoi;
  4. use App\Repository\TextLoiRepository;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Contracts\EventDispatcher\Event;
  7. use Symfony\Component\HttpKernel\KernelEvents;
  8. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  9. use Symfony\Component\Security\Http\Event\LogoutEvent;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. use Symfony\Component\Security\Core\Security;
  12. class LogoutSubscriber implements EventSubscriberInterface
  13. {
  14.     private $rtl;
  15.     private $entityManager;
  16.     private $security;
  17.     public function __construct(TextLoiRepository $rtl,EntityManagerInterface $em,Security $security)
  18.     {
  19.         $this->rtl=$rtl;
  20.         $this->entityManager=$em;
  21.         $this->security $security;
  22.     }
  23.     public static function getSubscribedEvents()
  24.     {
  25.         // return the subscribed events, their methods and priorities
  26.         return [
  27.             LogoutEvent::class =>['processLogout']
  28.         ];
  29.     }
  30.     public function processLogout(LogoutEvent $event)
  31.     {
  32.         $user $this->security->getUser();
  33.         if (!$user instanceof \App\Entity\User) {
  34.             return;
  35.         }
  36.         $societe $user->getSociete();
  37.         $nbTextLoi $this->rtl->countTextLoi();
  38.         $societe->setNbTextLoi($nbTextLoi);
  39.         $this->entityManager->flush();
  40.     }
  41.     
  42. }