src/EventListener/JWTAuthenticationSubscriber.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Entity\Customer;
  4. use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent;
  5. use Lexik\Bundle\JWTAuthenticationBundle\Events;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. /**
  8.  * Class JWTAuthenticationSubscriber.
  9.  */
  10. class JWTAuthenticationSubscriber implements EventSubscriberInterface
  11. {
  12.     /**
  13.      * {@inheritdoc}
  14.      */
  15.     public static function getSubscribedEvents()
  16.     {
  17.         // return the subscribed events, their methods and priorities
  18.         return array(
  19.             Events::JWT_CREATED => array(
  20.                 array('onJWTCreated'0),
  21.             ),
  22.         );
  23.     }
  24.     /**
  25.      * @param JWTCreatedEvent $event
  26.      */
  27.     public function onJWTCreated(JWTCreatedEvent $event)
  28.     {
  29.         $payload $event->getData();
  30.         $user $event->getUser();
  31.         $payload['type'] = get_class($user);
  32.         $payload['id'] = $user->getId();
  33.         if (Customer::class === $payload['type']) {
  34.             $payload['cachedIban'] = $user->getCachedIban();
  35.         }
  36.         $event->setData($payload);
  37.     }
  38. }