2

As you can see in the following links, the supportsClass & supportsAttribute methods aren't called when we call isGranted():

Does these methods being called in other places?

Why they are part of interface?

Community
  • 1
  • 1
Xuni
  • 604
  • 3
  • 13

1 Answers1

0

Sound like it's a normal behavior since the voter have to check for the class.

Here is a the solution to check the class :

function vote(TokenInterface $token, $object, array $attributes)
{   
    $user = $token->getUser();

    //sometime the object is a class or a instance of Request
    if($object instanceOf \Symfony\Component\HttpFoundation\Request ){
        return VoterInterface::ACCESS_ABSTAIN;   
    }else{
        $class = $object->getType();
        if($class == 'Vendor\\MyBundle\\Entity\\MyEntity'){
           return VoterInterface::ACCESS_GRANTED; 
        }
    }

    return VoterInterface::ACCESS_DENIED;   
}
Chopchop
  • 2,899
  • 18
  • 36