src/EventSubscriber/TwigEventSubscriber.php line 39
<?phpnamespace App\EventSubscriber;use App\Service\BasketContents;use App\Service\BasketContentsActionShock;use App\Service\CheckActiveUser;use App\Service\RetrieveRebate;use App\Service\RetrieveClients;use Doctrine\ORM\EntityManagerInterface;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\HttpFoundation\RedirectResponse;use Symfony\Component\HttpKernel\Event\ControllerEvent;use Symfony\Component\HttpKernel\HttpKernelInterface;use Symfony\Component\HttpKernel\KernelEvents;use Twig\Environment;class TwigEventSubscriber implements EventSubscriberInterface{private $twig;private $basketContents;private $checkActiveUser;private $manager;private $rebates;private $clients;private $basketContentsActionShock;public function __construct(Environment $twig, BasketContents $basketContents, EntityManagerInterface $manager, CheckActiveUser $checkActiveUser, RetrieveRebate $rebates, RetrieveClients $clients, BasketContentsActionShock $basketContentsActionShock){$this->twig = $twig;$this->basketContents = $basketContents;$this->manager = $manager;$this->checkActiveUser = $checkActiveUser;$this->rebates = $rebates;$this->clients = $clients;$this->basketContentsActionShock = $basketContentsActionShock;}public function onKernelController(ControllerEvent $event): void{$cartInfos = $this->basketContents->findBasketContent($this->manager);$this->twig->addGlobal('basketContents', $cartInfos->cartItemsCount);$this->twig->addGlobal('noRebateQty', $cartInfos->noRebateQty);$this->twig->addGlobal('rebates', $this->rebates->findAllActiveRebates($this->manager));$this->twig->addGlobal('rebateNatura', $this->rebates->findActiveRebatesBrand($this->manager, $this->rebates->findAllActiveRebates($this->manager)));$this->twig->addGlobal('clients', $this->clients->retrieveAllClients($this->manager));$this->twig->addGlobal('basketContentsActionShock', $this->basketContentsActionShock->findBasketContentActionShock($this->manager));$response = $this->checkActiveUser->checkIfActiveUser();if ($response instanceof RedirectResponse) {$event->setController(fn() => $response);$event->getRequest()->attributes->set('_controller', HttpKernelInterface::MAIN_REQUEST);}}public static function getSubscribedEvents(): array{return [KernelEvents::CONTROLLER => 'onKernelController',];}}