src/EventSubscriber/TheServiceSubscriber.php line 51

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use ApiPlatform\Symfony\EventListener\EventPriorities;
  4. use App\Constant\TimelineDataConstant;
  5. use App\Entity\Theservice;
  6. use App\Service\Api\Timeline\OtherMonitoring;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Symfony\Component\HttpKernel\Event\ViewEvent;
  9. use Symfony\Component\HttpKernel\KernelEvents;
  10. use Psr\Log\LoggerInterface;
  11. class TheServiceSubscriber implements EventSubscriberInterface
  12. {
  13.     /**
  14.      * @var OtherMonitoring
  15.      */
  16.     private $otherMonitoring;
  17.      /**
  18.      * @var LoggerInterface
  19.      */
  20.     private $logger;
  21.     /**
  22.      * @param OtherMonitoring $otherMonitoring
  23.      * @param LoggerInterface $logger
  24.      */
  25.     public function __construct(OtherMonitoring $otherMonitoringLoggerInterface $logger)
  26.     {
  27.         $this->otherMonitoring $otherMonitoring;
  28.         $this->logger $logger;
  29.     }
  30.     /**
  31.      *
  32.      * @return array
  33.      */
  34.     public static function getSubscribedEvents(): array
  35.     {
  36.         return [
  37.             KernelEvents::VIEW => ['onPostCreate'EventPriorities::POST_WRITE],
  38.         ];
  39.     }
  40.     /**
  41.      *
  42.      * @param ViewEvent $event
  43.      */
  44.     public function onPostCreate(ViewEvent $event): void
  45.     {
  46.         $entity $event->getControllerResult();
  47.         $method $event->getRequest()->getMethod();
  48.         if ($entity instanceof Theservice && $method === 'POST') {
  49.             try {
  50.                 $this->otherMonitoring->eventOnTheServiceCreation(
  51.                     $entity,
  52.                     TimelineDataConstant::SERVICE_PROXIMITY_CREATION,
  53.                     TimelineDataConstant::COLOR_THEMES['w-local']['variants']['service_proximity']
  54.                 );
  55.             } catch (\Exception $e) {
  56.                  $this->logger->error('Error during timeline creation for The service: ' $e->getMessage());
  57.             }
  58.         }
  59.     }
  60. }