src/PortoContainers/Zapier/EventSubscriber/InventorySubscriber.php line 36

  1. <?php
  2. namespace App\PortoContainers\Zapier\EventSubscriber;
  3. use App\Event\InventoryQuantityUpdatedEvent;
  4. use App\PortoContainers\Zapier\Actions\AddTriggerAction;
  5. use App\PortoContainers\Zapier\DTO\ZapierTriggerData;
  6. use App\PortoContainers\Zapier\Entities\ZapierTrigger;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class InventorySubscriber implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @param AddTriggerAction $addTriggerAction
  12.      */
  13.     public function __construct(
  14.         private readonly AddTriggerAction $addTriggerAction
  15.     )
  16.     {}
  17.     /**
  18.      * @return array
  19.      */
  20.     public static function getSubscribedEvents(): array
  21.     {
  22.         return [
  23.             InventoryQuantityUpdatedEvent::class => ['inventoryQuantityUpdated', -100],
  24.         ];
  25.     }
  26.     /**
  27.      * @param InventoryQuantityUpdatedEvent $event
  28.      * @return void
  29.      * @throws \Exception
  30.      */
  31.     public function inventoryQuantityUpdated(InventoryQuantityUpdatedEvent $event): void
  32.     {
  33.         $this->addTriggerAction->run(
  34.             new ZapierTriggerData(
  35.                 ZapierTrigger::TRIGGER_INVENTORY_UPDATED,
  36.                 $event->getInventory()->getId()
  37.             )
  38.         );
  39.     }
  40. }