src/EventListener/GetResponseListener.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Entity\Gos\User;
  4. use App\Utils\GetResponse\GetResponseContactCreator;
  5. use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationSuccessEvent;
  6. use Lexik\Bundle\JWTAuthenticationBundle\Events as JWTAuthenticationEvents;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
  9. use Symfony\Component\Security\Http\SecurityEvents;
  10. class GetResponseListener  implements EventSubscriberInterface
  11. {
  12.     private $getResponseContactCreator;
  13.     public function __construct(GetResponseContactCreator $getResponseContactCreator)
  14.     {
  15.         $this->getResponseContactCreator $getResponseContactCreator;
  16.     }
  17.     public static function getSubscribedEvents(): array
  18.     {
  19.         return [
  20.             SecurityEvents::INTERACTIVE_LOGIN               => ['onSecurityInteractiveLogin', -1],
  21.             JWTAuthenticationEvents::AUTHENTICATION_SUCCESS => 'onAuthenticationSuccessResponse',
  22.         ];
  23.     }
  24.     public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
  25.     {
  26.         $this->createGetResponseContact($event->getAuthenticationToken()->getUser());
  27.     }
  28.     public function onAuthenticationSuccessResponse(AuthenticationSuccessEvent $event)
  29.     {
  30.         $this->createGetResponseContact($event->getUser());
  31.     }
  32.     private function createGetResponseContact(User $user)
  33.     {
  34.         if ($user->getGetResponseContactId() === null) {
  35.             $this->getResponseContactCreator->addContact($user);
  36.         }
  37.     }
  38. }