11
11
12
12
namespace Symfony \Bundle \FrameworkBundle \DependencyInjection \Compiler ;
13
13
14
- use Symfony \Component \DependencyInjection \Compiler \PriorityTaggedServiceTrait ;
15
14
use Symfony \Component \DependencyInjection \ContainerBuilder ;
16
15
use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
17
16
use Symfony \Component \DependencyInjection \Exception \InvalidArgumentException ;
24
23
*/
25
24
class FormPass implements CompilerPassInterface
26
25
{
27
- use PriorityTaggedServiceTrait;
28
-
29
26
public function process (ContainerBuilder $ container )
30
27
{
31
28
if (!$ container ->hasDefinition ('form.extension ' )) {
@@ -49,23 +46,34 @@ public function process(ContainerBuilder $container)
49
46
50
47
$ definition ->replaceArgument (1 , $ types );
51
48
52
- $ typeExtensions = array ();
49
+ $ typeExtensionsToSort = array ();
53
50
54
- foreach ($ this ->findAndSortTaggedServices ('form.type_extension ' , $ container ) as $ reference ) {
55
- $ serviceId = (string ) $ reference ;
51
+ foreach ($ container ->findTaggedServiceIds ('form.type_extension ' ) as $ serviceId => $ tag ) {
56
52
$ serviceDefinition = $ container ->getDefinition ($ serviceId );
57
53
if (!$ serviceDefinition ->isPublic ()) {
58
54
throw new InvalidArgumentException (sprintf ('The service "%s" must be public as form type extensions are lazy-loaded. ' , $ serviceId ));
59
55
}
60
56
61
- $ tag = $ serviceDefinition ->getTag ('form.type_extension ' );
62
57
if (isset ($ tag [0 ]['extended_type ' ])) {
63
58
$ extendedType = $ tag [0 ]['extended_type ' ];
64
59
} else {
65
60
throw new InvalidArgumentException (sprintf ('Tagged form type extension must have the extended type configured using the extended_type/extended-type attribute, none was configured for the "%s" service. ' , $ serviceId ));
66
61
}
67
62
68
- $ typeExtensions [$ extendedType ][] = $ serviceId ;
63
+ $ typeExtensionsToSort [isset ($ tag [0 ]['priority ' ]) ? $ tag [0 ]['priority ' ] : 0 ][] = array (
64
+ 'service_id ' => $ serviceId ,
65
+ 'extended_type ' => $ extendedType ,
66
+ );
67
+ }
68
+
69
+ $ typeExtensions = array ();
70
+ if ($ typeExtensionsToSort ) {
71
+ krsort ($ typeExtensionsToSort );
72
+ $ typeExtensionsSorted = call_user_func_array ('array_merge ' , $ typeExtensionsToSort );
73
+
74
+ foreach ($ typeExtensionsSorted as $ typeExtension ) {
75
+ $ typeExtensions [$ typeExtension ['extended_type ' ]][] = $ typeExtension ['service_id ' ];
76
+ }
69
77
}
70
78
71
79
$ definition ->replaceArgument (2 , $ typeExtensions );
0 commit comments