src/EventSubscriber/TwigSubscriber.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Entity\TblSociete;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpKernel\Event\KernelEvent;
  7. use Symfony\Component\HttpKernel\KernelEvents;
  8. use Twig\Environment;
  9. class TwigSubscriber implements EventSubscriberInterface
  10. {
  11.      /**
  12.      * @var \Twig\Environment
  13.      */
  14.     private $twig;
  15.     /**
  16.      * @var \Doctrine\ORM\EntityManagerInterface
  17.      */
  18.     private $manager;
  19.     public function __constructEnvironment $twigEntityManagerInterface $manager ) {
  20.         $this->twig    $twig;
  21.         $this->manager $manager;
  22.     }
  23.     public function injectGlobalVariables($event) {
  24.         $societe $this->manager->getRepository(TblSociete::class)->find(1);
  25.         $nomSociete $societe $societe->getRaisonSocial() : 'AGRONET';
  26.         $this->twig->addGlobal'nomSociete'$nomSociete);
  27.     }
  28.     public static function getSubscribedEvents() {
  29.         return [ KernelEvents::CONTROLLER =>  'injectGlobalVariables' ];
  30.     }
  31. }