diff options
author | Nicolas Grekas <nicolas.grekas@gmail.com> | 2015-05-23 11:58:34 -0700 |
---|---|---|
committer | Nicolas Grekas <nicolas.grekas@gmail.com> | 2015-05-23 12:08:33 -0700 |
commit | 3c6c556ba36d68e6c05b8be761d35fb919825509 (patch) | |
tree | 7ffe78990f214978fd8260018b2e243422da9497 | |
parent | a3c3bf47ffef13bb4646f0c7b7971cce399d5950 (diff) | |
download | symfony-security-3c6c556ba36d68e6c05b8be761d35fb919825509.zip symfony-security-3c6c556ba36d68e6c05b8be761d35fb919825509.tar.gz symfony-security-3c6c556ba36d68e6c05b8be761d35fb919825509.tar.bz2 |
[Security] Add setVoters() on AccessDecisionManager
-rw-r--r-- | Core/Authorization/AccessDecisionManager.php | 16 | ||||
-rw-r--r-- | Core/Tests/Authorization/AccessDecisionManagerTest.php | 8 |
2 files changed, 11 insertions, 13 deletions
diff --git a/Core/Authorization/AccessDecisionManager.php b/Core/Authorization/AccessDecisionManager.php index b8b6a77..61debe3 100644 --- a/Core/Authorization/AccessDecisionManager.php +++ b/Core/Authorization/AccessDecisionManager.php @@ -41,12 +41,8 @@ class AccessDecisionManager implements AccessDecisionManagerInterface * * @throws \InvalidArgumentException */ - public function __construct(array $voters, $strategy = self::STRATEGY_AFFIRMATIVE, $allowIfAllAbstainDecisions = false, $allowIfEqualGrantedDeniedDecisions = true) + public function __construct(array $voters = array(), $strategy = self::STRATEGY_AFFIRMATIVE, $allowIfAllAbstainDecisions = false, $allowIfEqualGrantedDeniedDecisions = true) { - if (!$voters) { - throw new \InvalidArgumentException('You must at least add one voter.'); - } - $strategyMethod = 'decide'.ucfirst($strategy); if (!is_callable(array($this, $strategyMethod))) { throw new \InvalidArgumentException(sprintf('The strategy "%s" is not supported.', $strategy)); @@ -59,6 +55,16 @@ class AccessDecisionManager implements AccessDecisionManagerInterface } /** + * Configures the voters. + * + * @param VoterInterface[] $voters An array of VoterInterface instances + */ + public function setVoters(array $voters) + { + $this->voters = $voters; + } + + /** * {@inheritdoc} */ public function decide(TokenInterface $token, array $attributes, $object = null) diff --git a/Core/Tests/Authorization/AccessDecisionManagerTest.php b/Core/Tests/Authorization/AccessDecisionManagerTest.php index 3c970d1..bd876c7 100644 --- a/Core/Tests/Authorization/AccessDecisionManagerTest.php +++ b/Core/Tests/Authorization/AccessDecisionManagerTest.php @@ -49,14 +49,6 @@ class AccessDecisionManagerTest extends \PHPUnit_Framework_TestCase /** * @expectedException \InvalidArgumentException */ - public function testSetVotersEmpty() - { - $manager = new AccessDecisionManager(array()); - } - - /** - * @expectedException \InvalidArgumentException - */ public function testSetUnsupportedStrategy() { new AccessDecisionManager(array($this->getVoter(VoterInterface::ACCESS_GRANTED)), 'fooBar'); |