src/EventSubscriber/ControllerSubscriber.php line 30
<?php
namespace App\EventSubscriber;
use App\Service\BookingService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Twig\Environment;
class ControllerSubscriber implements EventSubscriberInterface
{
private BookingService $bookingService;
private Environment $twig;
public function __construct(BookingService $bookingService, Environment $twig)
{
//do something
$this->bookingService = $bookingService;
$this->twig = $twig;
}
public static function getSubscribedEvents()
{
//on controller event
return [
'kernel.controller' => 'onControllerEvent',
];
}
public function onControllerEvent(): void
{
$apiStatus = $this->bookingService->getApiUpdateStatus();
$this->twig->addGlobal('apiStatus', $apiStatus);
}
}