Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ea0598a

Browse filesBrowse files
committed
minor #10390 [Security] Add constants for access decision strategies (c960657)
This PR was merged into the 2.5-dev branch. Discussion ---------- [Security] Add constants for access decision strategies I suggest adding constants for the three access decision strategies (affirmative, consensus, unanimous). They are difficult to spell, and without constants they are difficult to identify when reading the code. | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | N/A | License | MIT | Doc PR | N/A Commits ------- 5d6ef00 Add class constants for access decision strategies.
2 parents 1e0fea6 + 5d6ef00 commit ea0598a
Copy full SHA for ea0598a

File tree

Expand file treeCollapse file tree

2 files changed

+24
-20
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+24
-20
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php
+5-1Lines changed: 5 additions & 1 deletion
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.');
Collapse file

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Tests/Authorization/AccessDecisionManagerTest.php
+19-19Lines changed: 19 additions & 19 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.