src/Products/NotificationsBundle/Subscriber/WebhookSubscriber.php line 55

Open in your IDE?
  1. <?php
  2. namespace Products\NotificationsBundle\Subscriber;
  3. use Cms\CoreBundle\Util\Doctrine\EntityManager;
  4. use Platform\QueueBundle\Event\AsyncEvent;
  5. use Products\NotificationsBundle\Service\ContactMonitor;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. final class WebhookSubscriber implements EventSubscriberInterface
  8. {
  9.     /**
  10.      * @var EntityManager
  11.      */
  12.     protected EntityManager $em;
  13.     /**
  14.      * @var ContactMonitor
  15.      */
  16.     protected ContactMonitor $monitor;
  17.     /**
  18.      * @param EntityManager $em
  19.      * @param ContactMonitor $monitor
  20.      */
  21.     public function __construct(EntityManager $emContactMonitor $monitor)
  22.     {
  23.         $this->em $em;
  24.         $this->monitor $monitor;
  25.     }
  26.     /**
  27.      * {@inheritDoc}
  28.      */
  29.     public static function getSubscribedEvents(): array
  30.     {
  31.         return [
  32.             ContactMonitor::EVENTS__WEBHOOKS__EMAIL => ['onWebhookEmail'0],
  33.             ContactMonitor::EVENTS__WEBHOOKS__SMS => ['onWebhookSms'0],
  34.             ContactMonitor::EVENTS__WEBHOOKS__VOICE => ['onWebhookVoice'0],
  35.         ];
  36.     }
  37.     /**
  38.      * @param AsyncEvent $event
  39.      */
  40.     public function onWebhookEmail(AsyncEvent $event)
  41.     {
  42.         $this->monitor->handleEmail($event->getBody()->all());
  43.     }
  44.     /**
  45.      * @param AsyncEvent $event
  46.      */
  47.     public function onWebhookSms(AsyncEvent $event)
  48.     {
  49.         $this->monitor->handleSms($event->getBody()->all());
  50.     }
  51.     /**
  52.      * @param AsyncEvent $event
  53.      */
  54.     public function onWebhookVoice(AsyncEvent $event)
  55.     {
  56.         $this->monitor->handleVoice($event->getBody()->all());
  57.     }
  58. }