src/Floa/Exception/FloaExceptionEventSubscriber.php line 42

Open in your IDE?
  1. <?php
  2. namespace App\Floa\Exception;
  3. use Crea\FloaBundle\Event\FloaExceptionEvent;
  4. use App\Helper\EmailSenderHelper;
  5. use Crea\FloaBundle\Normalizer\FloaExceptionNormalizer;
  6. use Crea\FloaBundle\Exception\AbstractFloaException;
  7. use Crea\FloaBundle\FloaEvents;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Symfony\Component\Serializer\Exception\ExceptionInterface;
  10. use Symfony\Component\Serializer\Serializer;
  11. use Throwable;
  12. class FloaExceptionEventSubscriber implements EventSubscriberInterface
  13. {
  14.     protected EmailSenderHelper $emailSenderHelper;
  15.     protected string $mailTo;
  16.     public function __construct(EmailSenderHelper $emailSenderHelperstring $mailTo)
  17.     {
  18.         $this->emailSenderHelper $emailSenderHelper;
  19.         $this->mailTo $mailTo;
  20.     }
  21.     public static function getSubscribedEvents(): array
  22.     {
  23.         return [
  24.             FloaEvents::MISSING_ADAPTER_EXCEPTION => [['handleException'256]],
  25.             FloaEvents::MISSING_ELIGIBILITY_EXCEPTION => [['handleException'256]],
  26.             FloaEvents::CLIENT_TOKEN_EXCEPTION => [['handleException'256]],
  27.             FloaEvents::CLIENT_PRE_ELIGIBILITY_EXCEPTION => [['handleException'256]],
  28.             FloaEvents::CLIENT_ELIGIBILITY_EXCEPTION => [['handleException'256]],
  29.             FloaEvents::CLIENT_PAYMENT_SESSION_EXCEPTION => [['handleException'256]],
  30.         ];
  31.     }
  32.     /**
  33.      * @throws ExceptionInterface
  34.      */
  35.     public function handleException(FloaExceptionEvent $event)
  36.     {
  37.         if ($this->supportException($exception $event->getException())) {
  38.             $serializer = new Serializer([new FloaExceptionNormalizer()]);
  39.             $this->emailSenderHelper->sendTextEmail(
  40.                 [$this->mailTo],
  41.                 "Floa exception",
  42.                 print_r($serializer->normalize($exception), true)
  43.             );
  44.         }
  45.     }
  46.     private function supportException(Throwable $exception): bool
  47.     {
  48.         return $exception instanceof AbstractFloaException;
  49.     }
  50. }