src/EventSubscriber/notifiers/ExploitationGlobalVariablesSubscriber.php line 16

  1. <?php
  2. namespace App\EventSubscriber\notifiers;
  3. use App\Services\notifiers\ExploitationGlobalVarService;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  6. use Twig\Environment;
  7. class ExploitationGlobalVariablesSubscriber implements EventSubscriberInterface
  8. {
  9.     public function __construct(
  10.         private readonly ExploitationGlobalVarService $globalVarService,
  11.         private readonly Environment $twig
  12.     ) {}
  13.     public function onKernelController(ControllerEvent $event): void
  14.     {
  15.         $vars $this->globalVarService->getGlobalVariables();
  16.         foreach ($vars as $key => $value) {
  17.             $this->twig->addGlobal($key$value);
  18.         }
  19.     }
  20.     public static function getSubscribedEvents(): array
  21.     {
  22.         return [
  23.             'kernel.controller' => 'onKernelController',
  24.         ];
  25.     }
  26. }