/** * {@inheritDoc} */ public function decide(RuleVoterInterface $voter, array $rules, array $attributes = []) { $grant = 0; $deny = 0; $abstain = 0; foreach ($rules as $rule) { $result = $voter->vote($rule, $attributes); switch ($result) { case RuleVoterInterface::ACCESS_GRANTED: ++$grant; break; case RuleVoterInterface::ACCESS_DENIED: ++$deny; break; default: ++$abstain; break; } } if ($grant > $deny) { return true; } if ($deny > $grant) { return false; } if ($grant == $deny && $grant != 0) { return $this->allowIfEqualGrantedDeniedDecisions; } return $this->allowIfAllAbstainDecisions; }
/** * {@inheritDoc} */ public function decide(RuleVoterInterface $voter, array $rules, array $attributes = []) { $deny = 0; foreach ($rules as $rule) { $result = $voter->vote($rule, $attributes); switch ($result) { case RuleVoterInterface::ACCESS_GRANTED: return true; case RuleVoterInterface::ACCESS_DENIED: ++$deny; break; default: break; } } if ($deny > 0) { return false; } return $this->allowIfAllAbstainDecisions; }