File tree 2 files changed +23
-20
lines changed
src/Symfony/Bundle/SecurityBundle
DependencyInjection/Compiler
Tests/DependencyInjection/Compiler
2 files changed +23
-20
lines changed Original file line number Diff line number Diff line change 11
11
12
12
namespace Symfony \Bundle \SecurityBundle \DependencyInjection \Compiler ;
13
13
14
- use Symfony \Component \DependencyInjection \Reference ;
15
14
use Symfony \Component \DependencyInjection \ContainerBuilder ;
16
15
use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
16
+ use Symfony \Component \DependencyInjection \Compiler \PriorityTaggedServiceTrait ;
17
17
use Symfony \Component \DependencyInjection \Exception \LogicException ;
18
18
19
19
/**
23
23
*/
24
24
class AddSecurityVotersPass implements CompilerPassInterface
25
25
{
26
+ use PriorityTaggedServiceTrait;
27
+
26
28
/**
27
29
* {@inheritdoc}
28
30
*/
@@ -32,15 +34,7 @@ public function process(ContainerBuilder $container)
32
34
return ;
33
35
}
34
36
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 );
44
38
if (!$ voters ) {
45
39
throw new LogicException ('No security voters found. You need to tag at least one with "security.voter" ' );
46
40
}
Original file line number Diff line number Diff line change 18
18
19
19
class AddSecurityVotersPassTest extends TestCase
20
20
{
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
+
21
36
public function testThatSecurityVotersAreProcessedInPriorityOrder ()
22
37
{
23
38
$ container = new ContainerBuilder ();
@@ -45,15 +60,9 @@ public function testThatSecurityVotersAreProcessedInPriorityOrder()
45
60
$ compilerPass ->process ($ container );
46
61
47
62
$ 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 );
58
67
}
59
68
}
You can’t perform that action at this time.
0 commit comments