<?php
namespace App\EventSubscriber;
use App\Service\UserService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Twig\Environment;
class UserSubscriber implements EventSubscriberInterface
{
private Environment $twig;
private UserService $userService;
public function __construct(Environment $twig, UserService $userService)
{
$this->twig = $twig;
$this->userService = $userService;
}
public function onKernelRequest(RequestEvent $event): void
{
if (!$event->isMainRequest()) {
return;
}
$session = new Session();
$this->twig->addGlobal('connected_as', ($session->get('connect_as_master') !== null));
$this->twig->addGlobal('currentInstitution', $this->userService->getCurrentInstitution());
}
public static function getSubscribedEvents(): array
{
return array(
KernelEvents::REQUEST => 'onKernelRequest',
);
}
}