src/Twig/LastNotifications.php line 56
<?phpnamespace App\Twig;use App\Entity\NotificationSystem;use Doctrine\ORM\EntityManagerInterface;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\HttpKernel\KernelEvents;use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;use Twig\Environment;/*** Class LastNotifications* @package App\Twig*/class LastNotifications implements EventSubscriberInterface{/*** @var Environment*/private Environment $twig;/*** @var EntityManagerInterface*/private EntityManagerInterface $manager;/*** @var TokenStorageInterface*/private TokenStorageInterface $storage;/*** LastNotifications constructor.* @param Environment $twig* @param EntityManagerInterface $manager* @param TokenStorageInterface $storage*/public function __construct(Environment $twig, EntityManagerInterface $manager, TokenStorageInterface $storage){$this->twig = $twig;$this->manager = $manager;$this->storage = $storage;}/*** @return array|string[]*/public static function getSubscribedEvents(){return [KernelEvents::CONTROLLER => 'notifications'];}public function notifications(){$token = $this->storage->getToken();if ($token) {$user = $token->getUser();if ($user === 'anon.') {return;}$notifications = $this->manager->getRepository(NotificationSystem::class)->getLastThree($user);$this->twig->addGlobal('lastNotifications', $notifications);}}}