I use security voters as an alternative to symfony acl.
voter example:
My voters look the same, following the following.
class FoobarVoter implements VoterInterface { public function supportsClass($class) { return in_array($class, array( 'Example\FoobarBundle\Entity\Foobar', )); } public function supportsAttribute($attribute) { return in_array(strtolower($attribute), array('foo', 'bar')); } public function vote(TokenInterface $token, $object, array $attributes) { $result = VoterInterface::ACCESS_ABSTAIN if (!$this->supportsClass(get_class($object))) { return VoterInterface::ACCESS_ABSTAIN; } foreach ($attributes as $attribute) { $attribute = strtolower($attribute);
questions:
reduce the number of calls to Voter :: vote ()
my voters are on and cause every page to load. even if they do not support solutions for this class. FoobarVoter::vote() always called. even if FoobarVoter::supportsClass() or FoobarVoter::supportsAttribute returns false. so I need to check the class and attribute inside FoobarVoter::vote() . is it a standard of behavior? how can i prevent this unnecessary call.
restrict voters
some voters are needed only in certain packages. some of them are only needed to define specific classes. therefore, some voters are not needed in all parts of my application. Is it possible to include voters dynamically in a bunch / entity? for example, include only voters in the decision manager chain if a specific node or object is accessed / used?
Martin abraham
source share