use App\Entity\User; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
protectedfunction voteOnAttribute(string $attribute,$subject, TokenInterface $token): bool { /** @var User $user */ $user=$token->getUser(); // $subjectRoles=$this->roleHierarchy->getReachableRoleNames($subject->getRoles()); $userRoles=$this->roleHierarchy->getReachableRoleNames($user->getRoles()); //je ne peux pas modifier un utilisateur ayant plus de rôles que moi if(count($subjectRoles)>count($userRoles)){ returnfalse; } returntrue; } }