src/EventListener/DiaboloResponseListener.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Entity\Gos\User;
  4. use App\Event\DiaboloResponseEvent;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class DiaboloResponseListener implements EventSubscriberInterface
  8. {
  9.     private $entityManager;
  10.     public function __construct(EntityManagerInterface $entityManager)
  11.     {
  12.         $this->entityManager $entityManager;
  13.     }
  14.     public static function getSubscribedEvents(): array
  15.     {
  16.         return [
  17.             DiaboloResponseEvent::DIABOLO_RESPONSE => 'onDiaboloResponse',
  18.         ];
  19.     }
  20.     public function onDiaboloResponse(DiaboloResponseEvent $event): void
  21.     {
  22.         $responseHttpCode $event->getResponseHttpCode();
  23.         $user $event->getUser();
  24.         if ($user instanceof User) {
  25.             $failureAt $responseHttpCode !== 200 ? new \DateTime() : null;
  26.             $user->setLastFailureDiaboloResponseAt($failureAt);
  27.             $this->entityManager->persist($user);
  28.             $this->entityManager->flush();
  29.         }
  30.     }
  31. }