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 58797f3

Browse filesBrowse files
committed
Use IteratorArgument for voters
1 parent b9b6ebd commit 58797f3
Copy full SHA for 58797f3

File tree

Expand file treeCollapse file tree

3 files changed

+23
-13
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+23
-13
lines changed

‎src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/AddSecurityVotersPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/AddSecurityVotersPass.php
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler;
1313

14+
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
1415
use Symfony\Component\DependencyInjection\Reference;
1516
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
@@ -45,7 +46,7 @@ public function process(ContainerBuilder $container)
4546
throw new LogicException('No security voters found. You need to tag at least one with "security.voter"');
4647
}
4748

48-
$adm = $container->getDefinition($container->hasDefinition('debug.security.access.decision_manager') ? 'debug.security.access.decision_manager' : 'security.access.decision_manager');
49-
$adm->addMethodCall('setVoters', array(array_values($voters)));
49+
$adm = $container->getDefinition('security.access.decision_manager');
50+
$adm->replaceArgument(0, new IteratorArgument(array_values($voters)));
5051
}
5152
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php
+11-9Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,14 @@ class AccessDecisionManager implements AccessDecisionManagerInterface
3232
private $allowIfEqualGrantedDeniedDecisions;
3333

3434
/**
35-
* Constructor.
36-
*
37-
* @param VoterInterface[] $voters An array of VoterInterface instances
38-
* @param string $strategy The vote strategy
39-
* @param bool $allowIfAllAbstainDecisions Whether to grant access if all voters abstained or not
40-
* @param bool $allowIfEqualGrantedDeniedDecisions Whether to grant access if result are equals
35+
* @param iterable|VoterInterface[] $voters An iterator of VoterInterface instances
36+
* @param string $strategy The vote strategy
37+
* @param bool $allowIfAllAbstainDecisions Whether to grant access if all voters abstained or not
38+
* @param bool $allowIfEqualGrantedDeniedDecisions Whether to grant access if result are equals
4139
*
4240
* @throws \InvalidArgumentException
4341
*/
44-
public function __construct(array $voters = array(), $strategy = self::STRATEGY_AFFIRMATIVE, $allowIfAllAbstainDecisions = false, $allowIfEqualGrantedDeniedDecisions = true)
42+
public function __construct($voters = array(), $strategy = self::STRATEGY_AFFIRMATIVE, $allowIfAllAbstainDecisions = false, $allowIfEqualGrantedDeniedDecisions = true)
4543
{
4644
$strategyMethod = 'decide'.ucfirst($strategy);
4745
if (!is_callable(array($this, $strategyMethod))) {
@@ -58,9 +56,13 @@ public function __construct(array $voters = array(), $strategy = self::STRATEGY_
5856
* Configures the voters.
5957
*
6058
* @param VoterInterface[] $voters An array of VoterInterface instances
59+
*
60+
* @deprecated since version 3.3, to be removed in 4.0. Pass the voters to the constructor instead.
6161
*/
6262
public function setVoters(array $voters)
6363
{
64+
@trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Pass the voters to the constructor instead.', __METHOD__), E_USER_DEPRECATED);
65+
6466
$this->voters = $voters;
6567
}
6668

@@ -162,8 +164,8 @@ private function decideConsensus(TokenInterface $token, array $attributes, $obje
162164
private function decideUnanimous(TokenInterface $token, array $attributes, $object = null)
163165
{
164166
$grant = 0;
165-
foreach ($attributes as $attribute) {
166-
foreach ($this->voters as $voter) {
167+
foreach ($this->voters as $voter) {
168+
foreach ($attributes as $attribute) {
167169
$result = $voter->vote($token, $object, array($attribute));
168170

169171
switch ($result) {

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Authorization/TraceableAccessDecisionManager.php
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ public function __construct(AccessDecisionManagerInterface $manager)
3333
$this->manager = $manager;
3434

3535
if ($this->manager instanceof AccessDecisionManager) {
36-
// The strategy is stored in a private property of the decorated service
36+
// The strategy and voters are stored in a private properties of the decorated service
3737
$reflection = new \ReflectionProperty(AccessDecisionManager::class, 'strategy');
3838
$reflection->setAccessible(true);
3939
$this->strategy = $reflection->getValue($manager);
40+
$reflection = new \ReflectionProperty(AccessDecisionManager::class, 'voters');
41+
$reflection->setAccessible(true);
42+
$this->voters = $reflection->getValue($manager);
4043
}
4144
}
4245

@@ -58,9 +61,13 @@ public function decide(TokenInterface $token, array $attributes, $object = null)
5861

5962
/**
6063
* {@inheritdoc}
64+
*
65+
* @deprecated since version 3.3, to be removed in 4.0. Pass voters to the decorated AccessDecisionManager instead.
6166
*/
6267
public function setVoters(array $voters)
6368
{
69+
@trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Pass voters to the decorated AccessDecisionManager instead.', __METHOD__), E_USER_DEPRECATED);
70+
6471
if (!method_exists($this->manager, 'setVoters')) {
6572
return;
6673
}
@@ -81,7 +88,7 @@ public function getStrategy()
8188
}
8289

8390
/**
84-
* @return array
91+
* @return iterable|VoterInterface[]
8592
*/
8693
public function getVoters()
8794
{

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.