I created a voter where I need to call is_granted for the user.
When injecting the security.authorization_checker service in my elector, I get the following error:
ServiceCircularReferenceException in CheckCircularReferencesPass.php line 69: A circular reference was found for the service "manager_voter", path: "manager_voter → security.authorization_checker → security.access.decision_manager → manager_voter".
Is there an alternative to injecting the entire container? This is normal?
EDIT:
I call the voter from the controller:
if (false === $this->get('security.authorization_checker')->isGranted('manage', $associate)) {
throw new AccessDeniedException('Unauthorised access!');
}
In this element, I have to check the user roles:
if ($this->container->get('security.authorization_checker')->isGranted('ROLE_COMPANY_MANAGER'))
{
return true;
}
This, of course, leads to a cycle. How not to get this loop? When calling $ user-> getRoles, the user will not take into account the hierarchy of the role, if I'm not mistaken.