src/EventListener/JWTCreatedListener.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent;
  4. use Symfony\Component\HttpFoundation\RequestStack;
  5. class JWTCreatedListener{
  6.     /**
  7.      * @var RequestStack
  8.      */
  9.     private $requestStack;
  10.     /**
  11.      * @param RequestStack $requestStack
  12.      */
  13.     public function __construct(RequestStack $requestStack)
  14.     {
  15.         $this->requestStack $requestStack;
  16.     }
  17.     /**
  18.      * @param JWTCreatedEvent $event
  19.      *
  20.      * @return void
  21.      */
  22.     public function onJWTCreated(JWTCreatedEvent $event)
  23.     {
  24.         $request $this->requestStack->getCurrentRequest();
  25.         $payload       $event->getData();
  26.         if($user $event->getUser()){
  27.             $payload['id']          = $user->getId();
  28.             $payload['civility']    = $user->getCivility();
  29.             $payload['firstname']   = $user->getFirstname();
  30.             $payload['lastname']    = $user->getLastname();
  31.             $payload['birthdate']   = $user->getBirthdate();
  32.             $payload['email']       = $user->getEmail();
  33.             $payload['phone']       = $user->getPhone();
  34.             $payload['mobile']      = $user->getMobile();
  35.             $payload['enabled']     = $user->isEnabled();
  36.             $payload['image']       = $user->getImage()?$user->getImage()->getPath().$user->getImage()->getName().'.'.$user->getImage()->getExtension():null;
  37.         }
  38.         $event->setData($payload);
  39.     }
  40. }