<?php
namespace App\EventSubscriber;
use App\Manager\FormsManager;
use App\Manager\InfoManager;
use App\Manager\ModelsManager;
use App\Manager\ServiceManager;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Twig\Environment;
class TwigEventSubscriber implements EventSubscriberInterface
{
private Environment $twig;
private InfoManager $infoManager;
private FormsManager $formsManager;
private ServiceManager $serviceManager;
private ModelsManager $modelsManager;
public function __construct(Environment $twig, InfoManager $infoManager, FormsManager $formsManager, ServiceManager $serviceManager, ModelsManager $modelsManager)
{
$this->twig = $twig;
$this->infoManager = $infoManager;
$this->formsManager = $formsManager;
$this->serviceManager = $serviceManager;
$this->modelsManager = $modelsManager;
}
public function onControllerEvent(ControllerEvent $event)
{
$info = $this->infoManager->find(1);
$forms = $this->formsManager->find(1);
$menuServices = $this->serviceManager->valid();
$menuModels = $this->modelsManager->find(1);
$this->twig->addGlobal('info', $info);
$this->twig->addGlobal('forms', $forms);
$this->twig->addGlobal('menu_services', $menuServices);
$this->twig->addGlobal('menu_models', $menuModels);
$this->twig->addGlobal('menu_active', []);
}
public static function getSubscribedEvents(): array
{
return [
ControllerEvent::class => 'onControllerEvent',
];
}
}