src/EventListener/KernelRequestListener.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Repository\CommandeRepository;
  4. use App\Service\CommandeService;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  7. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  8. use Symfony\Component\Routing\RouterInterface;
  9. use Symfony\Component\HttpFoundation\RedirectResponse;
  10. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  11. use Twig\Environment;
  12. class KernelRequestListener
  13. {
  14.     protected $token;
  15.     protected $router;
  16.     protected $twig;
  17.     protected $commandeService;
  18.     public function __construct(RouterInterface $routerTokenStorageInterface $token_storageEntityManagerInterface $emSessionInterface $sessionEnvironment $twigCommandeService $commandeService)
  19.     {
  20.         $this->token $token_storage;
  21.         $this->router $router;
  22.         $this->twig $twig;
  23.         $this->commandeService $commandeService;
  24.     }
  25.     public function onKernelRequest(GetResponseEvent $event)
  26.     {
  27.         $request $event->getRequest();
  28.         if ($event->isMasterRequest() && $this->token->getToken() && $this->token->getToken()->getUser() != 'anon.') {
  29.             if ($this->token->getToken()->getUser()->isTemporaryPassword() && $request->attributes->get('_route') != 'change_password') {
  30.                 $event->setResponse(new RedirectResponse($this->router->generate('change_password')));
  31.                 $this->twig->addGlobal('panierTotal'0);
  32.             } else {
  33.                 $panier $this->commandeService->getPanier($this->token->getToken()->getUser());
  34.                 $this->twig->addGlobal('panierTotal', (($panier) ? count($panier) : ));
  35.             }
  36.         }
  37.         return;
  38.     }
  39. }