<?php
namespace App\EventSubscriber;
use App\Repository\ClientDebitRepository;
use phpDocumentor\Reflection\Types\This;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Twig\Environment;
class TwigEventSubscriber implements EventSubscriberInterface
{
private $twig;
/**
* @var ClientDebitRepository
*/
private $clientDebitRepository;
public function __construct(Environment $twig, ClientDebitRepository $clientDebitRepository)
{
$this->twig = $twig;
$this->clientDebitRepository = $clientDebitRepository;
}
public function onControllerEvent(ControllerEvent $event)
{
$request = $event->getRequest();
$this->twig->addGlobal('route_name', $request->attributes->get('_route'));
$pendingFacturations = count($this->clientDebitRepository->findBy(['deleted' => false, 'paid' => false]));
$this->twig->addGlobal('pendingFacturations', $pendingFacturations);
}
public static function getSubscribedEvents()
{
return [
ControllerEvent::class => 'onControllerEvent',
];
}
}