<?php
namespace App\EventSubscriber;
use App\Manager\BrandManager;
use App\Manager\FormsManager;
use App\Manager\InfoManager;
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 BrandManager $brandManager;
private ServiceManager $serviceManager;
public function __construct(Environment $twig, InfoManager $infoManager, FormsManager $formsManager, BrandManager $brandManager, ServiceManager $serviceManager)
{
$this->twig = $twig;
$this->infoManager = $infoManager;
$this->formsManager = $formsManager;
$this->brandManager = $brandManager;
$this->serviceManager = $serviceManager;
}
public function onControllerEvent(ControllerEvent $event)
{
$info = $this->infoManager->find(1);
$forms = $this->formsManager->find(1);
$menuBrands = $this->brandManager->valid();
$menuServices = $this->serviceManager->valid();
$this->twig->addGlobal('info', $info);
$this->twig->addGlobal('forms', $forms);
$this->twig->addGlobal('menu_brands', $menuBrands);
$this->twig->addGlobal('menu_services', $menuServices);
$this->twig->addGlobal('menu_active', []);
}
public static function getSubscribedEvents(): array
{
return [
ControllerEvent::class => 'onControllerEvent',
];
}
}