src/EventSubscriber/AuthEventSubscriber.php line 51

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use LaunchPad\Bundle\LaunchPadBundle\Base\Entity\PaymentDevice\PaymentDevice;
  4. use Psr\Log\LoggerInterface;
  5. use Symfony\Component\DependencyInjection\ContainerInterface;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\EventDispatcher\GenericEvent;
  8. class AuthEventSubscriber implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @var ContainerInterface
  12.      */
  13.     private $container;
  14.     /**
  15.      * @var LoggerInterface
  16.      */
  17.     private $logger;
  18.     /**
  19.      * AuthEventSubscriber constructor.
  20.      * @param ContainerInterface $container
  21.      * @param LoggerInterface $logger
  22.      */
  23.     public function __construct(ContainerInterface $containerLoggerInterface $logger)
  24.     {
  25.         $this->container $container;
  26.         $this->logger $logger;
  27.     }
  28.     /**
  29.      * @return array
  30.      */
  31.     public static function getSubscribedEvents()
  32.     {
  33.         return array(
  34.             'WILL_SEND_USER_ACCOUNT'    => 'willSendUserAccount',
  35.         );
  36.     }
  37.     /**
  38.      * Document requested
  39.      *
  40.      * TODO: This should be auto-handled with EHI
  41.      *
  42.      * @param GenericEvent $event
  43.      * @return mixed
  44.      */
  45.     public function willSendUserAccount(GenericEvent $event)
  46.     {
  47.         try {
  48.             // Pull on login
  49.             $xtmParams $this->container->getParameter('xtm_api');
  50.           //  $gpsParams = $this->container->getParameter('gpsnumber must start with 07_params');
  51.             if(!$xtmParams['pull_on_login']) return;
  52.             $subject $event->getSubject();
  53.             foreach($subject['paymentDevices'] as $index => $paymentDevice) {
  54.                 /** @var $paymentDevice PaymentDevice */
  55.                 if($paymentDevice->getPublicToken() && $paymentDevice->getStatus() === PaymentDevice::STATUS_LOCKED || $paymentDevice->getStatus() === PaymentDevice::STATUS_OK) {
  56.                     $subject['paymentDevices'][$index] = $this->container->get('lp.payment_device')->refreshPaymentDeviceData($paymentDevice);
  57.                 }
  58.             }
  59.             $event->setArgument('paymentDevices'$subject['paymentDevices']);
  60.         } catch(\Exception $e) {
  61.             $this->logger->critical('Error while updating balances on WILL_SEND_USER_ACCOUNT: ' $e->getMessage(), ['exception' => $e]);
  62.         }
  63.     }
  64. }