8000 Merge branch '2.7' into 2.8 · symfony/symfony@8201e47 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 8201e47

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: fix priority ordering of security voters
2 parents 4584fad + b675d05 commit 8201e47

File tree

2 files changed

+64
-5
lines changed

2 files changed

+64
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ public function process(ContainerBuilder $container)
3232
return;
3333
}
3434

35-
$voters = new \SplPriorityQueue();
35+
$voters = array();
3636
foreach ($container->findTaggedServiceIds('security.voter') as $id => $attributes) {
3737
$priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
38-
$voters->insert(new Reference($id), $priority);
38+
$voters[$priority][] = new Reference($id);
3939
}
4040

41-
$voters = iterator_to_array($voters);
42-
ksort($voters);
41+
krsort($voters);
42+
$voters = call_user_func_array('array_merge', $voters);
4343

4444
if (!$voters) {
4545
throw new LogicException('No security voters found. You need to tag at least one with "security.voter"');
4646
}
4747

48-
$container->getDefinition('security.access.decision_manager')->addMethodCall('setVoters', array(array_values($voters)));
48+
$container->getDefinition('security.access.decision_manager')->addMethodCall('setVoters', array($voters));
4949
}
5050
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection\Compiler;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler\AddSecurityVotersPass;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
use Symfony\Component\DependencyInjection\Reference;
18+
19+
class AddSecurityVotersPassTest extends TestCase
20+
{
21+
public function testThatSecurityVotersAreProcessedInPriorityOrder()
22+
{
23+
$container = new ContainerBuilder();
24+
$container
25+
->register('security.access.decision_manager', 'Symfony\Component\Security\Core\Authorization\AccessDecisionManager')
26+
->addArgument(array())
27+
;
28+
$container
29+
->register('no_prio_service')
30+
->addTag('security.voter')
31+
;
32+
$container
33+
->register('lowest_prio_service')
34+
->addTag('security.voter', array('priority' => 100))
35+
;
36+
$container
37+
->register('highest_prio_service')
38+
->addTag('security.voter', array('priority' => 200))
39+
;
40+
$container
41+
->register('zero_prio_service')
42+
->addTag('security.voter', array('priority' => 0))
43+
;
44+
$compilerPass = new AddSecurityVotersPass();
45+
$compilerPass->process($container);
46+
47+
$calls = $container->getDefinition('security.access.decision_manager')->getMethodCalls();
48+
49+
$this->assertEquals(
50+
array(
51+
new Reference('highest_prio_service'),
52+
new Reference('lowest_prio_service'),
53+
new Reference('no_prio_service'),
54+
new Reference('zero_prio_service'),
55+
),
56+
$calls[0][1][0]
57+
);
58+
}
59+
}

0 commit comments

Comments
 (0)
0