Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5d6ef00

Browse files
author
Christian Schmidt
committed
Add class constants for access decision strategies.
1 parent f15ea50 commit 5d6ef00

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
*/
2323
class AccessDecisionManager implements AccessDecisionManagerInterface
2424
{
25+
const STRATEGY_AFFIRMATIVE = 'affirmative';
26+
const STRATEGY_CONSENSUS = 'consensus';
27+
const STRATEGY_UNANIMOUS = 'unanimous';
28+
2529
private $voters;
2630
private $strategy;
2731
private $allowIfAllAbstainDecisions;
@@ -37,7 +41,7 @@ class AccessDecisionManager implements AccessDecisionManagerInterface
3741
*
3842
* @throws \InvalidArgumentException
3943
*/
40-
public function __construct(array $voters, $strategy = 'affirmative', $allowIfAllAbstainDecisions = false, $allowIfEqualGrantedDeniedDecisions = true)
44+
public function __construct(array $voters, $strategy = self::STRATEGY_AFFIRMATIVE, $allowIfAllAbstainDecisions = false, $allowIfEqualGrantedDeniedDecisions = true)
4145
{
4246
if (!$voters) {
4347
throw new \InvalidArgumentException('You must at least add one voter.');

src/Symfony/Component/Security/Core/Tests/Authorization/AccessDecisionManagerTest.php

+19-19
Original file line numberDiff line numberDiff line change
@@ -77,34 +77,34 @@ public function getStrategyTests()
7777
{
7878
return array(
7979
// affirmative
80-
array('affirmative', $this->getVoters(1, 0, 0), false, true, true),
81-
array('affirmative', $this->getVoters(1, 2, 0), false, true, true),
82-
array('affirmative', $this->getVoters(0, 1, 0), false, true, false),
83-
array('affirmative', $this->getVoters(0, 0, 1), false, true, false),
84-
array('affirmative', $this->getVoters(0, 0, 1), true, true, true),
80+
array(AccessDecisionManager::STRATEGY_AFFIRMATIVE, $this->getVoters(1, 0, 0), false, true, true),
81+
array(AccessDecisionManager::STRATEGY_AFFIRMATIVE, $this->getVoters(1, 2, 0), false, true, true),
82+
array(AccessDecisionManager::STRATEGY_AFFIRMATIVE, $this->getVoters(0, 1, 0), false, true, false),
83+
array(AccessDecisionManager::STRATEGY_AFFIRMATIVE, $this->getVoters(0, 0, 1), false, true, false),
84+
array(AccessDecisionManager::STRATEGY_AFFIRMATIVE, $this->getVoters(0, 0, 1), true, true, true),
8585

8686
// consensus
87-
array('consensus', $this->getVoters(1, 0, 0), false, true, true),
88-
array('consensus', $this->getVoters(1, 2, 0), false, true, false),
89-
array('consensus', $this->getVoters(2, 1, 0), false, true, true),
87+
array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(1, 0, 0), false, true, true),
88+
array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(1, 2, 0), false, true, false),
89+
array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(2, 1, 0), false, true, true),
9090

91-
array('consensus', $this->getVoters(0, 0, 1), false, true, false),
91+
array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(0, 0, 1), false, true, false),
9292

93-
array('consensus', $this->getVoters(0, 0, 1), true, true, true),
93+
array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(0, 0, 1), true, true, true),
9494

95-
array('consensus', $this->getVoters(2, 2, 0), false, true, true),
96-
array('consensus', $this->getVoters(2, 2, 1), false, true, true),
95+
array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(2, 2, 0), false, true, true),
96+
array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(2, 2, 1), false, true, true),
9797

98-
array('consensus', $this->getVoters(2, 2, 0), false, false, false),
99-
array('consensus', $this->getVoters(2, 2, 1), false, false, false),
98+
array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(2, 2, 0), false, false, false),
99+
array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(2, 2, 1), false, false, false),
100100

101101
// unanimous
102-
array('unanimous', $this->getVoters(1, 0, 0), false, true, true),
103-
array('unanimous', $this->getVoters(1, 0, 1), false, true, true),
104-
array('unanimous', $this->getVoters(1, 1, 0), false, true, false),
102+
array(AccessDecisionManager::STRATEGY_UNANIMOUS, $this->getVoters(1, 0, 0), false, true, true),
103+
array(AccessDecisionManager::STRATEGY_UNANIMOUS, $this->getVoters(1, 0, 1), false, true, true),
104+
array(AccessDecisionManager::STRATEGY_UNANIMOUS, $this->getVoters(1, 1, 0), false, true, false),
105105

106-
array('unanimous', $this->getVoters(0, 0, 2), false, true, false),
107-
array('unanimous', $this->getVoters(0, 0, 2), true, true, true),
106+
array(AccessDecisionManager::STRATEGY_UNANIMOUS, $this->getVoters(0, 0, 2), false, true, false),
107+
array(AccessDecisionManager::STRATEGY_UNANIMOUS, $this->getVoters(0, 0, 2), true, true, true),
108108
);
109109
}
110110

0 commit comments

Comments
 (0)