src/Twig/TwigGlobalSubscriber.php line 36
<?phpnamespace App\Twig;use Doctrine\ORM\EntityManagerInterface;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\HttpKernel\KernelEvents;use Twig\Environment;use Symfony\Component\HttpKernel\Event\ControllerEvent;use App\Entity\Courier;use App\Entity\Shipment;use App\Entity\TrackingStatus;use App\Entity\Customer;use Symfony\Component\Security\Core\Security;class TwigGlobalSubscriber implements EventSubscriberInterface{/*** @var \Twig\Environment*/private $twig;/*** @var \Doctrine\ORM\EntityManagerInterface*/private $manager;private $security;public function __construct(Environment $twig, EntityManagerInterface $manager, Security $security) {$this->twig = $twig;$this->manager = $manager;$this->security = $security;}public function injectGlobalVariables( ControllerEvent $event ) {$courierList = $this->manager->getRepository(Courier::class)->findAll();$this->twig->addGlobal( 'gloCourierList', $courierList);if($this->security->getUser() !== null){$customerList = $this->manager->getRepository(Customer::class)->findBy(['userCompany' => $this->security->getUser()->getUserCompany()->getId()], ['name' => 'ASC']);$this->twig->addGlobal( 'gloCustomerList', $customerList);}$totalBooking = $this->manager->getRepository(Shipment::class)->getTotalCountShipment();$this->twig->addGlobal( 'totalBookingMenu', $totalBooking);$trackingStatusList = $this->manager->getRepository(TrackingStatus::class)->findAll();$this->twig->addGlobal( 'gloTrackingStatusList', $trackingStatusList);}public static function getSubscribedEvents() {return [ KernelEvents::CONTROLLER => 'injectGlobalVariables' ];}}