eventDispatcher = $dispatcher; $this->storage = $storage; } public static function getSubscribedEvents(): array { return [ KernelEvents::CONTROLLER => ['prepareUserProfile', 200] ]; } public function prepareUserProfile(KernelEvent $event): void { // ignore sub-requests if (!$event->isMasterRequest()) { return; } // ignore events like the toolbar where we do not have a token if (null === ($token = $this->storage->getToken())) { return; } $user = $token->getUser(); if ($user instanceof User) { $event = new PrepareUserEvent($user); $this->eventDispatcher->dispatch($event); } } }