src/EventSubscriber/TwigEventSubscriber.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Repository\ClientDebitRepository;
  4. use phpDocumentor\Reflection\Types\This;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  8. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  9. use Twig\Environment;
  10. class TwigEventSubscriber implements EventSubscriberInterface
  11. {
  12.     private $twig;
  13.     /**
  14.      * @var ClientDebitRepository
  15.      */
  16.     private $clientDebitRepository;
  17.     public function __construct(Environment $twigClientDebitRepository $clientDebitRepository)
  18.     {
  19.         $this->twig $twig;
  20.         $this->clientDebitRepository $clientDebitRepository;
  21.     }
  22.     public function onControllerEvent(ControllerEvent $event)
  23.     {
  24.         $request $event->getRequest();
  25.         $this->twig->addGlobal('route_name'$request->attributes->get('_route'));
  26.         $pendingFacturations count($this->clientDebitRepository->findBy(['deleted' => false'paid' => false]));
  27.         $this->twig->addGlobal('pendingFacturations'$pendingFacturations);
  28.     }
  29.     public static function getSubscribedEvents()
  30.     {
  31.         return [
  32.             ControllerEvent::class => 'onControllerEvent',
  33.         ];
  34.     }
  35. }