src/EventSubscriber/GroupSubscriber.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Service\GroupService;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpKernel\KernelEvents;
  6. use Twig\Environment;
  7. class GroupSubscriber implements EventSubscriberInterface
  8. {
  9.     private Environment $twig;
  10.     private GroupService $groupService;
  11.     public function __construct(
  12.         Environment $twig,
  13.         GroupService $groupService
  14.     ) {
  15.         $this->twig $twig;
  16.         $this->groupService $groupService;
  17.     }
  18.     public function onKernelController(): void
  19.     {
  20.         $this->twig->addGlobal('currentGroup'$this->groupService->getCurrentGroup());
  21.     }
  22.     public static function getSubscribedEvents(): array
  23.     {
  24.         return array(
  25.             KernelEvents::CONTROLLER => 'onKernelController',
  26.         );
  27.     }
  28. }