src/Twig/UserNotifications.php line 30
<?phpdeclare(strict_types=1);namespace App\Twig;use App\Repository\NotificationRepository;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\HttpKernel\KernelEvents;use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;use Twig\Environment;final class UserNotifications implements EventSubscriberInterface{public function __construct(private readonly Environment $twig,private readonly TokenStorageInterface $storage,private readonly NotificationRepository $notificationRepository){}public static function getSubscribedEvents(): array{return [KernelEvents::CONTROLLER => 'getNotifications'];}public function getNotifications(): void{$token = $this->storage->getToken();if ($token) {$user = $token->getUser();if (null === $user) {return;}$notifications = $this->notificationRepository->getLastThree($user);$this->twig->addGlobal('lastNotifications', $notifications);}}}