src/EventSubscriber/GlobalsSubscriber.php line 45

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpKernel\KernelEvents;
  5. use Twig\Environment;
  6. use App\Repository\ProjectRepository;
  7. use App\Repository\ClientRepository;
  8. use App\Repository\UserRepository;
  9. use App\Repository\TaskRepository;
  10. use App\Repository\TagOrgRepository;
  11. use App\Repository\TagTypeRepository;
  12. use Symfony\Component\Form\FormFactoryInterface;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. class GlobalsSubscriber extends AbstractController implements EventSubscriberInterface
  15. {
  16.     private $twig;
  17.     private $clientRepository;
  18.     private $projectRepository;
  19.     private $userRepository;
  20.     private $taskRepository;
  21.     private $tagTypeRepository;
  22.     private $tagOrgRepository;
  23.     
  24.     public function __construct(Environment $twig, ClientRepository $clientRepository, ProjectRepository $projectRepository, UserRepository $userRepository, TaskRepository $taskRepository, TagOrgRepository $tagOrgRepository, TagTypeRepository $tagTypeRepository, FormFactoryInterface $formFactory)
  25.     {
  26.         $this->twig = $twig;
  27.         $this->clientRepository = $clientRepository;
  28.         $this->projectRepository = $projectRepository;
  29.         $this->userRepository = $userRepository;
  30.         $this->taskRepository = $taskRepository;
  31.         $this->tagOrgRepository = $tagOrgRepository;
  32.         $this->tagTypeRepository = $tagTypeRepository;
  33.     }
  34.     public static function getSubscribedEvents()
  35.     {
  36.         return [
  37.             KernelEvents::REQUEST => 'onKernelRequest',
  38.         ];
  39.     }
  40.     public function onKernelRequest()
  41.     {
  42.         $this->twig->addGlobal('global_variable', 'valeur');
  43.         $this->twig->addGlobal('projects', $this->projectRepository->FindByActive());
  44.         $this->twig->addGlobal('users', $this->userRepository->findByNotArchived());
  45.         $this->twig->addGlobal('clients', $this->clientRepository->findAll());
  46.         $this->twig->addGlobal('tasks', $this->taskRepository->findByIdUserAffected());
  47.         $this->twig->addGlobal('todayTasks', $this->taskRepository->findByTodayTask());
  48.         $this->twig->addGlobal('threeDayTasks', $this->taskRepository->findByThreeDayTask());
  49.         $this->twig->addGlobal('formerTasks', $this->taskRepository->findByFormerTask());
  50.         $this->twig->addGlobal('tagOrgs', $this->tagOrgRepository->findAll());
  51.         $this->twig->addGlobal('tagTypes', $this->tagTypeRepository->findAll());
  52.     }
  53. }