<?php
namespace App\EventListener;
use App\Entity\Customer;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent;
use Lexik\Bundle\JWTAuthenticationBundle\Events;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Class JWTAuthenticationSubscriber.
*/
class JWTAuthenticationSubscriber implements EventSubscriberInterface
{
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
// return the subscribed events, their methods and priorities
return array(
Events::JWT_CREATED => array(
array('onJWTCreated', 0),
),
);
}
/**
* @param JWTCreatedEvent $event
*/
public function onJWTCreated(JWTCreatedEvent $event)
{
$payload = $event->getData();
$user = $event->getUser();
$payload['type'] = get_class($user);
$payload['id'] = $user->getId();
if (Customer::class === $payload['type']) {
$payload['cachedIban'] = $user->getCachedIban();
}
$event->setData($payload);
}
}