src/EventSubscriber/TwigEventSubscriber.php line 25

  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Repository\BranchOfficeRepository;
  4. use App\Repository\HeaderRepository;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  7. use Symfony\Component\HttpKernel\KernelEvents;
  8. use Twig\Environment;
  9. class TwigEventSubscriber implements EventSubscriberInterface
  10. {
  11.     private $twig;
  12.     private $branchOfficeRepository;
  13.     private $headerRepository;
  14.     public function __construct(Environment $twigBranchOfficeRepository $branchOfficeRepositoryHeaderRepository $headerRepository)
  15.     {
  16.         $this->twig $twig;
  17.         $this->branchOfficeRepository $branchOfficeRepository;
  18.         $this->headerRepository $headerRepository;
  19.     }
  20.     public function onKernelController(ControllerEvent $event): void
  21.     {
  22.         $this->twig->addGlobal('branch_offices'$this->branchOfficeRepository->findAll());
  23.         $this->twig->addGlobal('header'$this->headerRepository->findOneBy([]));
  24.     }
  25.     public static function getSubscribedEvents(): array
  26.     {
  27.         return [
  28.             KernelEvents::CONTROLLER => 'onKernelController',
  29.         ];
  30.     }
  31. }