Skip to content
This repository was archived by the owner on May 31, 2024. It is now read-only.

Commit 3c6c556

Browse files
[Security] Add setVoters() on AccessDecisionManager
1 parent a3c3bf4 commit 3c6c556

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

Core/Authorization/AccessDecisionManager.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,8 @@ class AccessDecisionManager implements AccessDecisionManagerInterface
4141
*
4242
* @throws \InvalidArgumentException
4343
*/
44-
public function __construct(array $voters, $strategy = self::STRATEGY_AFFIRMATIVE, $allowIfAllAbstainDecisions = false, $allowIfEqualGrantedDeniedDecisions = true)
44+
public function __construct(array $voters = array(), $strategy = self::STRATEGY_AFFIRMATIVE, $allowIfAllAbstainDecisions = false, $allowIfEqualGrantedDeniedDecisions = true)
4545
{
46-
if (!$voters) {
47-
throw new \InvalidArgumentException('You must at least add one voter.');
48-
}
49-
5046
$strategyMethod = 'decide'.ucfirst($strategy);
5147
if (!is_callable(array($this, $strategyMethod))) {
5248
throw new \InvalidArgumentException(sprintf('The strategy "%s" is not supported.', $strategy));
@@ -58,6 +54,16 @@ public function __construct(array $voters, $strategy = self::STRATEGY_AFFIRMATIV
5854
$this->allowIfEqualGrantedDeniedDecisions = (bool) $allowIfEqualGrantedDeniedDecisions;
5955
}
6056

57+
/**
58+
* Configures the voters.
59+
*
60+
* @param VoterInterface[] $voters An array of VoterInterface instances
61+
*/
62+
public function setVoters(array $voters)
63+
{
64+
$this->voters = $voters;
65+
}
66+
6167
/**
6268
* {@inheritdoc}
6369
*/

Core/Tests/Authorization/AccessDecisionManagerTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,6 @@ public function testSupportsAttribute()
4646
$this->assertFalse($manager->supportsAttribute('foo'));
4747
}
4848

49-
/**
50-
* @expectedException \InvalidArgumentException
51-
*/
52-
public function testSetVotersEmpty()
53-
{
54-
$manager = new AccessDecisionManager(array());
55-
}
56-
5749
/**
5850
* @expectedException \InvalidArgumentException
5951
*/

0 commit comments

Comments
 (0)