<?php
namespace App\EventSubscriber;
use App\Service\GroupService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Twig\Environment;
class GroupSubscriber implements EventSubscriberInterface
{
private Environment $twig;
private GroupService $groupService;
public function __construct(
Environment $twig,
GroupService $groupService
) {
$this->twig = $twig;
$this->groupService = $groupService;
}
public function onKernelController(): void
{
$this->twig->addGlobal('currentGroup', $this->groupService->getCurrentGroup());
}
public static function getSubscribedEvents(): array
{
return array(
KernelEvents::CONTROLLER => 'onKernelController',
);
}
}