src/EventSubscriber/TwigEventSubscriber.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use Twig\Environment;
  4. use App\Manager\InfoManager;
  5. use App\Manager\MessageErrorManager;
  6. use App\Manager\{ServiceManagerCategoryManagerFormsManager};
  7. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. class TwigEventSubscriber implements EventSubscriberInterface
  10. {
  11.     private Environment $twig;
  12.     private InfoManager $info;
  13.     private FormsManager $forms;
  14.     private CategoryManager $category;
  15.     private ServiceManager $service;
  16.     private MessageErrorManager $error;
  17.     public function __construct(Environment $twigInfoManager $infoMessageErrorManager $errorServiceManager $serviceCategoryManager $categoryFormsManager $forms)
  18.     {
  19.         $this->twig $twig;
  20.         $this->info $info;
  21.         $this->error $error;
  22.         $this->forms $forms;
  23.         $this->category $category;
  24.         $this->service $service;
  25.     }
  26.     public function onControllerEvent(ControllerEvent $event)
  27.     {
  28.         $info $this->info->find(1);
  29.         $error $this->error->find(1);
  30.         $forms $this->forms->find(1);
  31.         $categories $this->category->listActiveMenu();
  32.         $service $this->service->listActiveMenu();
  33.         $this->twig->addGlobal('info'$info);
  34.         $this->twig->addGlobal('forms'$forms);
  35.         $this->twig->addGlobal('msge'$error);
  36.         $this->twig->addGlobal('categories_menu'$categories);
  37.         $this->twig->addGlobal('services_menu'$service);
  38.         $this->twig->addGlobal('menu_active', []);
  39.     }
  40.     public static function getSubscribedEvents(): array
  41.     {
  42.         return [
  43.             ControllerEvent::class => 'onControllerEvent',
  44.         ];
  45.     }
  46. }