resolver = $resolver; $this->entityManager = $entityManager; } final protected function voteOnAttribute($attribute, $subject, TokenInterface $token) { $user = $token->getUser(); // if the user is anonymous, we use the anonymous user. if (!$user instanceof User) { $user = $this->entityManager->find(User::class, User::ID_ANONYMOUS); if (null === $user) { return false; } } return $this->voteOnUser($attribute, $subject, $user); } /** * Similar to voteOnAttribute, but checking for the anonymous user is already done. * The current user (or the anonymous user) is passed by $user. * * @param $attribute * @param $subject * @param User $user * * @return bool */ abstract protected function voteOnUser($attribute, $subject, User $user): bool; }