src/EventSubscriber/ControllerSubscriber.php line 30

  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Service\BookingService;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Twig\Environment;
  6. class ControllerSubscriber implements EventSubscriberInterface
  7. {
  8.     private BookingService $bookingService;
  9.     private Environment $twig;
  10.     public function __construct(BookingService $bookingServiceEnvironment $twig)
  11.     {
  12.         //do something
  13.         $this->bookingService $bookingService;
  14.         $this->twig $twig;
  15.     }
  16.     public static function getSubscribedEvents()
  17.     {
  18.        //on controller event
  19.         return [
  20.             'kernel.controller' => 'onControllerEvent',
  21.         ];
  22.     }
  23.     public function onControllerEvent(): void
  24.     {
  25.         $apiStatus $this->bookingService->getApiUpdateStatus();
  26.         $this->twig->addGlobal('apiStatus'$apiStatus);
  27.     }
  28. }