File tree Expand file tree Collapse file tree 2 files changed +23
-20
lines changed
src/Symfony/Bundle/SecurityBundle
DependencyInjection/Compiler
Tests/DependencyInjection/Compiler Expand file tree Collapse file tree 2 files changed +23
-20
lines changed Original file line number Diff line number Diff line change 1111
1212namespace Symfony \Bundle \SecurityBundle \DependencyInjection \Compiler ;
1313
14- use Symfony \Component \DependencyInjection \Reference ;
1514use Symfony \Component \DependencyInjection \ContainerBuilder ;
1615use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
16+ use Symfony \Component \DependencyInjection \Compiler \PriorityTaggedServiceTrait ;
1717use Symfony \Component \DependencyInjection \Exception \LogicException ;
1818
1919/**
2323 */
2424class AddSecurityVotersPass implements CompilerPassInterface
2525{
26+ use PriorityTaggedServiceTrait;
27+
2628 /**
2729 * {@inheritdoc}
2830 */
@@ -32,15 +34,7 @@ public function process(ContainerBuilder $container)
3234 return ;
3335 }
3436
35- $ voters = array ();
36- foreach ($ container ->findTaggedServiceIds ('security.voter ' ) as $ id => $ attributes ) {
37- $ priority = isset ($ attributes [0 ]['priority ' ]) ? $ attributes [0 ]['priority ' ] : 0 ;
38- $ voters [$ priority ][] = new Reference ($ id );
39- }
40-
41- krsort ($ voters );
42- $ voters = call_user_func_array ('array_merge ' , $ voters );
43-
37+ $ voters = $ this ->findAndSortTaggedServices ('security.voter ' , $ container );
4438 if (!$ voters ) {
4539 throw new LogicException ('No security voters found. You need to tag at least one with "security.voter" ' );
4640 }
Original file line number Diff line number Diff line change 1818
1919class AddSecurityVotersPassTest extends TestCase
2020{
21+ /**
22+ * @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException
23+ */
24+ public function testNoVoters ()
25+ {
26+ $ container = new ContainerBuilder ();
27+ $ container
28+ ->register ('security.access.decision_manager ' , 'Symfony\Component\Security\Core\Authorization\AccessDecisionManager ' )
29+ ->addArgument (array ())
30+ ;
31+
32+ $ compilerPass = new AddSecurityVotersPass ();
33+ $ compilerPass ->process ($ container );
34+ }
35+
2136 public function testThatSecurityVotersAreProcessedInPriorityOrder ()
2237 {
2338 $ container = new ContainerBuilder ();
@@ -45,15 +60,9 @@ public function testThatSecurityVotersAreProcessedInPriorityOrder()
4560 $ compilerPass ->process ($ container );
4661
4762 $ 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- );
63+ $ refs = $ calls [0 ][1 ][0 ];
64+ $ this ->assertEquals (new Reference ('highest_prio_service ' ), $ refs [0 ]);
65+ $ this ->assertEquals (new Reference ('lowest_prio_service ' ), $ refs [1 ]);
66+ $ this ->assertCount (4 , $ refs );
5867 }
5968}
You can’t perform that action at this time.
0 commit comments