src/Twig/TwigGlobalSubscriber.php line 32
<?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;class TwigGlobalSubscriber implements EventSubscriberInterface{/*** @var \Twig\Environment*/private $twig;/*** @var \Doctrine\ORM\EntityManagerInterface*/private $manager;public function __construct(Environment $twig, EntityManagerInterface $manager) {$this->twig = $twig;$this->manager = $manager;}public function injectGlobalVariables( ControllerEvent $event ) {$courierList = $this->manager->getRepository(Courier::class)->findAll();$this->twig->addGlobal( 'gloCourierList', $courierList);$customerList = $this->manager->getRepository(Customer::class)->findBy([], ['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' ];}}