@@ -156,6 +156,8 @@ public function buildContext(ContainerBuilder $container, array $config): void
156
156
->setFactory ([new Reference ($ factoryId ), 'createContext ' ])
157
157
;
158
158
159
+ $ this ->addServiceToLocator ($ container , 'context ' );
160
+
159
161
if ('default ' === $ this ->name ) {
160
162
$ container ->setAlias (Context::class, $ this ->format ('context ' ));
161
163
}
@@ -187,14 +189,8 @@ public function buildQueueConsumer(ContainerBuilder $container, array $config):
187
189
188
190
$ container ->register ($ this ->format ('processor_registry ' ), ContainerProcessorRegistry::class);
189
191
190
- $ locatorId = 'enqueue.locator ' ;
191
- if ($ container ->hasDefinition ($ locatorId )) {
192
- $ locator = $ container ->getDefinition ($ locatorId );
193
- $ locator ->replaceArgument (0 , array_replace ($ locator ->getArgument (0 ), [
194
- $ this ->format ('queue_consumer ' ) => new Reference ($ this ->format ('queue_consumer ' )),
195
- $ this ->format ('processor_registry ' ) => new Reference ($ this ->format ('processor_registry ' )),
196
- ]));
197
- }
192
+ $ this ->addServiceToLocator ($ container , 'queue_consumer ' );
193
+ $ this ->addServiceToLocator ($ container , 'processor_registry ' );
198
194
199
195
if ('default ' === $ this ->name ) {
200
196
$ container ->setAlias (QueueConsumerInterface::class, $ this ->format ('queue_consumer ' ));
@@ -226,4 +222,18 @@ private function assertServiceExists(ContainerBuilder $container, string $servic
226
222
throw new \InvalidArgumentException (sprintf ('The service "%s" does not exist. ' , $ serviceId ));
227
223
}
228
224
}
225
+
226
+ private function addServiceToLocator (ContainerBuilder $ container , string $ serviceName ): void
227
+ {
228
+ $ locatorId = 'enqueue.locator ' ;
229
+
230
+ if ($ container ->hasDefinition ($ locatorId )) {
231
+ $ locator = $ container ->getDefinition ($ locatorId );
232
+
233
+ $ map = $ locator ->getArgument (0 );
234
+ $ map [$ this ->format ($ serviceName )] = $ this ->reference ($ serviceName ));
235
+
236
+ $ locator ->replaceArgument (0 , $ map );
237
+ }
238
+ }
229
239
}
0 commit comments