src/Service/Panel/Api/Zapier/EventSubscriber/ZapierNotificationSubscriber.php line 46

Open in your IDE?
  1. <?php
  2. namespace Harmonizely\Service\Panel\Api\Zapier\EventSubscriber;
  3. use Harmonizely\Background\Data\ZapierNotificationData;
  4. use Harmonizely\CalendarEvents;
  5. use Harmonizely\Core\BackgroundWork\Contract\IClient;
  6. use Harmonizely\Model\Event;
  7. use Harmonizely\Types\ZapierNotificationType;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Symfony\Component\EventDispatcher\GenericEvent;
  10. class ZapierNotificationSubscriber implements EventSubscriberInterface
  11. {
  12.     /**
  13.      * @var IClient
  14.      */
  15.     private IClient $backgroundClient;
  16.     /**
  17.      * @param IClient $backgroundClient
  18.      */
  19.     public function __construct(IClient $backgroundClient)
  20.     {
  21.         $this->backgroundClient $backgroundClient;
  22.     }
  23.     /**
  24.      * @return string[]
  25.      */
  26.     public static function getSubscribedEvents(): array
  27.     {
  28.         return [
  29.             CalendarEvents::EVENT_POST_CREATE => 'create',
  30.             CalendarEvents::EVENT_POST_RESCHEDULE => 'reschedule',
  31.             CalendarEvents::EVENT_POST_CANCEL => 'cancel',
  32.         ];
  33.     }
  34.     /**
  35.      * @param GenericEvent $genericEvent
  36.      * @return void
  37.      */
  38.     public function create(GenericEvent $genericEvent): void
  39.     {
  40.         /** @var Event $event */
  41.         $event $genericEvent->getSubject();
  42.         $this->backgroundClient->add(new ZapierNotificationData(ZapierNotificationType::TYPE_EVENT_CREATE$event->getId()));
  43.         $this->backgroundClient->runJobs();
  44.     }
  45.     /**
  46.      * @param GenericEvent $genericEvent
  47.      * @return void
  48.      */
  49.     public function reschedule(GenericEvent $genericEvent): void
  50.     {
  51.         /** @var Event $event */
  52.         $event $genericEvent->getSubject();
  53.         $this->backgroundClient->add(new ZapierNotificationData(ZapierNotificationType::TYPE_EVENT_RESCHEDULE$event->getId()));
  54.         $this->backgroundClient->runJobs();
  55.     }
  56.     /**
  57.      * @param GenericEvent $genericEvent
  58.      * @return void
  59.      */
  60.     public function cancel(GenericEvent $genericEvent): void
  61.     {
  62.         /** @var Event $event */
  63.         $event $genericEvent->getSubject();
  64.         $this->backgroundClient->add(new ZapierNotificationData(ZapierNotificationType::TYPE_EVENT_CANCEL$event->getId()));
  65.         $this->backgroundClient->runJobs();
  66.     }
  67. }