src/EventSubscriber/UserSubscriber.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Service\UserService;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpFoundation\Session\Session;
  6. use Symfony\Component\HttpKernel\Event\RequestEvent;
  7. use Symfony\Component\HttpKernel\KernelEvents;
  8. use Twig\Environment;
  9. class UserSubscriber implements EventSubscriberInterface
  10. {
  11.     private Environment $twig;
  12.     private UserService $userService;
  13.     public function __construct(Environment $twigUserService $userService)
  14.     {
  15.         $this->twig $twig;
  16.         $this->userService $userService;
  17.     }
  18.     public function onKernelRequest(RequestEvent $event): void
  19.     {
  20.         if (!$event->isMainRequest()) {
  21.             return;
  22.         }
  23.         $session = new Session();
  24.         $this->twig->addGlobal('connected_as', ($session->get('connect_as_master') !== null));
  25.         $this->twig->addGlobal('currentInstitution'$this->userService->getCurrentInstitution());
  26.     }
  27.     public static function getSubscribedEvents(): array
  28.     {
  29.         return array(
  30.             KernelEvents::REQUEST => 'onKernelRequest',
  31.         );
  32.     }
  33. }