src/EventSubscriber/WebhookSendSubscriber.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Service\WebhookAttemptService;
  4. use Psr\Log\LoggerInterface;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpKernel\Event\TerminateEvent;
  7. use Symfony\Component\HttpKernel\KernelEvents;
  8. class WebhookSendSubscriber implements EventSubscriberInterface
  9. {
  10.     private WebhookAttemptService $service;
  11.     private LoggerInterface $logger;
  12.     public function __construct(WebhookAttemptService $serviceLoggerInterface $logger) {
  13.         $this->service $service;
  14.         $this->logger $logger;
  15.     }
  16.     public static function getSubscribedEvents(): array
  17.     {
  18.         return [KernelEvents::TERMINATE => 'sendWebookAsync'];
  19.     }
  20.     public function sendWebookAsync(TerminateEvent $event): void {
  21.         $request $event->getRequest();
  22.         $asyncSendStorage $request->attributes->get(WebhookAttemptService::ASYNC_SENDnull);
  23.         if(false === is_null($asyncSendStorage) && true === is_array($asyncSendStorage)) {
  24.             array_map(function($webhookAttemptId) {
  25.                 $this->service->sendWebhookById($webhookAttemptId);
  26.             }, $asyncSendStorage);
  27.         }
  28.     }
  29. }