<?php
namespace App\EventSubscriber;
use Twig\Environment;
use App\Manager\InfoManager;
use App\Manager\MessageErrorManager;
use App\Manager\{ServiceManager, CategoryManager, FormsManager};
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class TwigEventSubscriber implements EventSubscriberInterface
{
private Environment $twig;
private InfoManager $info;
private FormsManager $forms;
private CategoryManager $category;
private ServiceManager $service;
private MessageErrorManager $error;
public function __construct(Environment $twig, InfoManager $info, MessageErrorManager $error, ServiceManager $service, CategoryManager $category, FormsManager $forms)
{
$this->twig = $twig;
$this->info = $info;
$this->error = $error;
$this->forms = $forms;
$this->category = $category;
$this->service = $service;
}
public function onControllerEvent(ControllerEvent $event)
{
$info = $this->info->find(1);
$error = $this->error->find(1);
$forms = $this->forms->find(1);
$categories = $this->category->listActiveMenu();
$service = $this->service->listActiveMenu();
$this->twig->addGlobal('info', $info);
$this->twig->addGlobal('forms', $forms);
$this->twig->addGlobal('msge', $error);
$this->twig->addGlobal('categories_menu', $categories);
$this->twig->addGlobal('services_menu', $service);
$this->twig->addGlobal('menu_active', []);
}
public static function getSubscribedEvents(): array
{
return [
ControllerEvent::class => 'onControllerEvent',
];
}
}