1414use Symfony \Component \DependencyInjection \Reference ;
1515use Symfony \Component \DependencyInjection \ContainerBuilder ;
1616use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
17+ use Symfony \Component \DependencyInjection \Compiler \PriorityTaggedServiceTrait ;
1718use Symfony \Component \DependencyInjection \Exception \LogicException ;
1819
1920/**
2324 */
2425class AddSecurityVotersPassimplements CompilerPassInterface
2526{
27+ use PriorityTaggedServiceTrait;
28+
2629/**
2730 * {@inheritdoc}
2831 */
@@ -32,20 +35,7 @@ public function process(ContainerBuilder $container)
3235return ;
3336 }
3437
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-
44- if (!$ voters ) {
45- throw new LogicException ('No security voters found. You need to tag at least one with "security.voter" ' );
46- }
47-
4838$ adm =$ container ->getDefinition ($ container ->hasDefinition ('debug.security.access.decision_manager ' ) ?'debug.security.access.decision_manager ' :'security.access.decision_manager ' );
49- $ adm ->addMethodCall ('setVoters ' ,array ($ voters ));
39+ $ adm ->addMethodCall ('setVoters ' ,array ($ this -> findAndSortTaggedServices ( ' security.voter ' , $ container ) ));
5040 }
5141}