public vote ( Symfony\Component\Security\Core\Authentication\Token\TokenInterface $token, object $object, array $attributes ) : integer | ||
$token | Symfony\Component\Security\Core\Authentication\Token\TokenInterface | A TokenInterface instance |
$object | object | The object to secure |
$attributes | array | An array of attributes associated with the method being invoked |
Résultat | integer | either ACCESS_GRANTED, ACCESS_ABSTAIN, or ACCESS_DENIED |
public function vote(TokenInterface $token, $object, array $attributes)
{
foreach ($attributes as $attribute) {
if ($this->supportsAttribute($attribute)) {
$targets = isset($attribute->limitations['targets']) ? $attribute->limitations['targets'] : null;
if ($this->repository->canUser($attribute->module, $attribute->function, $attribute->limitations['valueObject'], $targets) === false) {
return VoterInterface::ACCESS_DENIED;
}
return VoterInterface::ACCESS_GRANTED;
}
}
return VoterInterface::ACCESS_ABSTAIN;
}
/** * @dataProvider voteProvider */ public function testVote(Attribute $attribute, $repositoryCanUser, $expectedResult) { $voter = new ValueObjectVoter($this->repository); $targets = isset($attribute->limitations['targets']) ? $attribute->limitations['targets'] : null; $this->repository->expects($this->once())->method('canUser')->with($attribute->module, $attribute->function, $attribute->limitations['valueObject'], $targets)->will($this->returnValue($repositoryCanUser)); $this->assertSame($expectedResult, $voter->vote($this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface'), new \stdClass(), array($attribute))); }