src/Security/Voter/AdminUserVoter.php line 11
<?phpnamespace App\Security\Voter;use App\Entity\User;use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;use Symfony\Component\Security\Core\Authorization\Voter\Voter;use Symfony\Component\Security\Core\Security;use Symfony\Component\Security\Core\User\UserInterface;class AdminUserVoter extends Voter{private Security $security;public function __construct(Security $security){$this->security = $security;}protected function supports(string $attribute, $subject): bool{// replace with your own logic// https://symfony.com/doc/current/security/voters.htmlreturn in_array($attribute, ['ADMIN_USER_EDIT'])&& $subject instanceof User;}protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool{$user = $token->getUser();if (!$subject instanceof User) {throw new \LogicException('Subject is not an instance of User?');}// ... (check conditions and return true to grant permission) ...switch ($attribute) {case 'ADMIN_USER_EDIT':return $user === $subject || $this->security->isGranted('ROLE_SUPER_ADMIN');}return false;}}