<?php
namespace Products\NotificationsBundle\Subscriber;
use Cms\CoreBundle\Util\Doctrine\EntityManager;
use Platform\QueueBundle\Event\AsyncEvent;
use Products\NotificationsBundle\Service\ContactMonitor;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
final class WebhookSubscriber implements EventSubscriberInterface
{
/**
* @var EntityManager
*/
protected EntityManager $em;
/**
* @var ContactMonitor
*/
protected ContactMonitor $monitor;
/**
* @param EntityManager $em
* @param ContactMonitor $monitor
*/
public function __construct(EntityManager $em, ContactMonitor $monitor)
{
$this->em = $em;
$this->monitor = $monitor;
}
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents(): array
{
return [
ContactMonitor::EVENTS__WEBHOOKS__EMAIL => ['onWebhookEmail', 0],
ContactMonitor::EVENTS__WEBHOOKS__SMS => ['onWebhookSms', 0],
ContactMonitor::EVENTS__WEBHOOKS__VOICE => ['onWebhookVoice', 0],
];
}
/**
* @param AsyncEvent $event
*/
public function onWebhookEmail(AsyncEvent $event)
{
$this->monitor->handleEmail($event->getBody()->all());
}
/**
* @param AsyncEvent $event
*/
public function onWebhookSms(AsyncEvent $event)
{
$this->monitor->handleSms($event->getBody()->all());
}
/**
* @param AsyncEvent $event
*/
public function onWebhookVoice(AsyncEvent $event)
{
$this->monitor->handleVoice($event->getBody()->all());
}
}