I have implemented the following Voter
Service definition
security.access.company_voter:
class: Application\...\CompanyVoter
public: false
tags:
- { name: security.voter }
Voter Application/.../CompanyVoter.php
#...
public function vote(TokenInterface $token, $object, array $attributes)
{
if ( !($this->supportsClass(get_class($object))) ) { # <- Problem here
return VoterInterface::ACCESS_ABSTAIN;
}
foreach ($attributes as $attribute) {
if ( !$this->supportsAttribute($attribute) ) {
return VoterInterface::ACCESS_ABSTAIN;
}
}
$user = $token->getUser();
if ( !($user instanceof UserInterface) ) {
return VoterInterface::ACCESS_DENIED;
}
if ( $user->getCompany() == $object->getCompany() ) {
return VoterInterface::ACCESS_GRANTED;
}
return VoterInterface::ACCESS_ABSTAIN;
}
#...
But every little call to the voter (except the first Symfony\Component\HttpFoundation\Request
) is giving an instance of Application\...\CompanyVoter
as $object
(2nd argument of vote()
).
What can be the reason ?