@@ -61,7 +61,7 @@ public function process(ContainerBuilder $container)
61
61
} else {
62
62
$ aliases = [];
63
63
}
64
- $ definition = $ container ->findDefinition ($ this ->dispatcherService );
64
+ $ globalDispatcherDefinition = $ container ->findDefinition ($ this ->dispatcherService );
65
65
66
66
foreach ($ container ->findTaggedServiceIds ($ this ->listenerTag , true ) as $ id => $ events ) {
67
67
foreach ($ events as $ event ) {
@@ -90,7 +90,12 @@ public function process(ContainerBuilder $container)
90
90
}
91
91
}
92
92
93
- $ definition ->addMethodCall ('addListener ' , [$ event ['event ' ], [new ServiceClosureArgument (new Reference ($ id )), $ event ['method ' ]], $ priority ]);
93
+ $ dispatcherDefinition = $ globalDispatcherDefinition ;
94
+ if (isset ($ event ['dispatcher ' ])) {
95
+ $ dispatcherDefinition = $ container ->getDefinition ($ event ['dispatcher ' ]);
96
+ }
97
+
98
+ $ dispatcherDefinition ->addMethodCall ('addListener ' , [$ event ['event ' ], [new ServiceClosureArgument (new Reference ($ id )), $ event ['method ' ]], $ priority ]);
94
99
95
100
if (isset ($ this ->hotPathEvents [$ event ['event ' ]])) {
96
101
$ container ->getDefinition ($ id )->addTag ($ this ->hotPathTagName );
@@ -100,7 +105,7 @@ public function process(ContainerBuilder $container)
100
105
101
106
$ extractingDispatcher = new ExtractingEventDispatcher ();
102
107
103
- foreach ($ container ->findTaggedServiceIds ($ this ->subscriberTag , true ) as $ id => $ attributes ) {
108
+ foreach ($ container ->findTaggedServiceIds ($ this ->subscriberTag , true ) as $ id => $ tags ) {
104
109
$ def = $ container ->getDefinition ($ id );
105
110
106
111
// We must assume that the class value has been correctly filled, even if the service is created by a factory
@@ -114,12 +119,27 @@ public function process(ContainerBuilder $container)
114
119
}
115
120
$ class = $ r ->name ;
116
121
122
+ $ dispatcherDefinitions = [];
123
+ foreach ($ tags as $ attributes ) {
124
+ if (!isset ($ attributes ['dispatcher ' ]) || isset ($ dispatcherDefinitions [$ attributes ['dispatcher ' ]])) {
125
+ continue ;
126
+ }
127
+
128
+ $ dispatcherDefinitions [] = $ container ->getDefinition ($ attributes ['dispatcher ' ]);
129
+ }
130
+
131
+ if ([] === $ dispatcherDefinitions ) {
132
+ $ dispatcherDefinitions = [$ globalDispatcherDefinition ];
133
+ }
134
+
117
135
ExtractingEventDispatcher::$ aliases = $ aliases ;
118
136
ExtractingEventDispatcher::$ subscriber = $ class ;
119
137
$ extractingDispatcher ->addSubscriber ($ extractingDispatcher );
120
138
foreach ($ extractingDispatcher ->listeners as $ args ) {
121
139
$ args [1 ] = [new ServiceClosureArgument (new Reference ($ id )), $ args [1 ]];
122
- $ definition ->addMethodCall ('addListener ' , $ args );
140
+ foreach ($ dispatcherDefinitions as $ dispatcherDefinition ) {
141
+ $ dispatcherDefinition ->addMethodCall ('addListener ' , $ args );
142
+ }
123
143
124
144
if (isset ($ this ->hotPathEvents [$ args [0 ]])) {
125
145
$ container ->getDefinition ($ id )->addTag ($ this ->hotPathTagName );
0 commit comments