4
4
5
5
use Enqueue \AsyncCommand \DependencyInjection \AsyncCommandExtension ;
6
6
use Enqueue \AsyncEventDispatcher \DependencyInjection \AsyncEventDispatcherExtension ;
7
+ use Enqueue \Bundle \Consumption \Extension \DoctrineClearIdentityMapExtension ;
8
+ use Enqueue \Bundle \Consumption \Extension \DoctrinePingConnectionExtension ;
7
9
use Enqueue \Client \CommandSubscriberInterface ;
8
10
use Enqueue \Client \TopicSubscriberInterface ;
11
+ use Enqueue \Consumption \Extension \ReplyExtension ;
12
+ use Enqueue \Consumption \Extension \SignalExtension ;
9
13
use Enqueue \JobQueue \Job ;
14
+ use Enqueue \Monitoring \Symfony \DependencyInjection \MonitoringFactory ;
10
15
use Enqueue \Symfony \Client \DependencyInjection \ClientFactory ;
11
16
use Enqueue \Symfony \DependencyInjection \TransportFactory ;
12
17
use Symfony \Component \Config \FileLocator ;
13
18
use Symfony \Component \Config \Resource \FileResource ;
14
19
use Symfony \Component \DependencyInjection \ContainerBuilder ;
15
20
use Symfony \Component \DependencyInjection \Extension \PrependExtensionInterface ;
16
21
use Symfony \Component \DependencyInjection \Loader \YamlFileLoader ;
22
+ use Symfony \Component \DependencyInjection \Reference ;
17
23
use Symfony \Component \HttpKernel \DependencyInjection \Extension ;
18
24
19
25
final class EnqueueExtension extends Extension implements PrependExtensionInterface
@@ -46,25 +52,36 @@ public function load(array $configs, ContainerBuilder $container): void
46
52
$ transportNames [] = $ name ;
47
53
48
54
$ transportFactory = (new TransportFactory ($ name ));
49
- $ transportFactory ->buildConnectionFactory ($ container , $ config ['transport ' ]);
55
+ $ transportFactory ->buildConnectionFactory ($ container , $ configs ['transport ' ]);
50
56
$ transportFactory ->buildContext ($ container , []);
51
- $ transportFactory ->buildQueueConsumer ($ container , $ config ['consumption ' ]);
57
+ $ transportFactory ->buildQueueConsumer ($ container , $ configs ['consumption ' ]);
52
58
$ transportFactory ->buildRpcClient ($ container , []);
53
59
54
60
// client
55
61
if (isset ($ configs ['client ' ])) {
56
62
$ clientNames [] = $ name ;
57
63
58
- $ clientConfig = $ config ['client ' ];
64
+ $ clientConfig = $ configs ['client ' ];
59
65
// todo
60
- $ clientConfig ['transport ' ] = $ config ['transport ' ];
61
- $ clientConfig ['consumption ' ] = $ config ['consumption ' ];
66
+ $ clientConfig ['transport ' ] = $ configs ['transport ' ];
67
+ $ clientConfig ['consumption ' ] = $ configs ['consumption ' ];
62
68
63
69
$ clientFactory = new ClientFactory ($ name );
64
70
$ clientFactory ->build ($ container , $ clientConfig , $ defaultName === $ name );
65
- $ clientFactory ->createDriver ($ container , $ config ['transport ' ]);
71
+ $ clientFactory ->createDriver ($ container , $ configs ['transport ' ]);
66
72
$ clientFactory ->createFlushSpoolProducerListener ($ container );
67
73
}
74
+
75
+ // monitoring
76
+ if (isset ($ configs ['monitoring ' ])) {
77
+ $ monitoringFactory = new MonitoringFactory ($ name );
78
+ $ monitoringFactory ->buildStorage ($ container , $ configs ['monitoring ' ]);
79
+ $ monitoringFactory ->buildConsumerExtension ($ container , $ configs ['monitoring ' ]);
80
+
81
+ if (isset ($ configs ['client ' ])) {
82
+ $ monitoringFactory ->buildClientExtension ($ container , $ configs ['monitoring ' ]);
83
+ }
84
+ }
68
85
}
69
86
70
87
$ container ->setParameter ('enqueue.transports ' , $ transportNames );
@@ -74,54 +91,34 @@ public function load(array $configs, ContainerBuilder $container): void
74
91
$ this ->setupAutowiringForProcessors ($ container , $ clientNames );
75
92
}
76
93
77
- // @todo register MessageQueueCollector
78
-
79
- return ;
80
-
81
- //
82
- if ($ config ['job ' ]) {
83
- if (!class_exists (Job::class)) {
84
- throw new \LogicException ('Seems "enqueue/job-queue" is not installed. Please fix this issue. ' );
85
- }
86
-
87
- $ loader ->load ('job.yml ' );
88
- }
89
-
90
- if ($ config ['async_events ' ]['enabled ' ]) {
91
- if (false == class_exists (AsyncEventDispatcherExtension::class)) {
92
- throw new \LogicException ('The "enqueue/async-event-dispatcher" package has to be installed. ' );
93
- }
94
-
95
- $ extension = new AsyncEventDispatcherExtension ();
96
- $ extension ->load ([[
97
- 'context_service ' => 'enqueue.transport.default.context ' ,
98
- ]], $ container );
99
- }
100
-
101
- if ($ config ['async_commands ' ]['enabled ' ]) {
102
- if (false == class_exists (AsyncCommandExtension::class)) {
103
- throw new \LogicException ('The "enqueue/async-command" package has to be installed. ' );
104
- }
94
+ $ this ->loadAsyncCommands ($ config , $ container );
105
95
106
- $ extension = new AsyncCommandExtension ();
107
- $ extension ->load ([[]], $ container );
108
- }
109
-
110
- if ($ config ['extensions ' ]['doctrine_ping_connection_extension ' ]) {
111
- $ loader ->load ('extensions/doctrine_ping_connection_extension.yml ' );
112
- }
113
-
114
- if ($ config ['extensions ' ]['doctrine_clear_identity_map_extension ' ]) {
115
- $ loader ->load ('extensions/doctrine_clear_identity_map_extension.yml ' );
116
- }
96
+ // extensions
97
+ $ this ->loadDoctrinePingConnectionExtension ($ config , $ container );
98
+ $ this ->loadDoctrineClearIdentityMapExtension ($ config , $ container );
99
+ $ this ->loadSignalExtension ($ config , $ container );
100
+ $ this ->loadReplyExtension ($ config , $ container );
117
101
118
- if ($ config ['extensions ' ]['signal_extension ' ]) {
119
- $ loader ->load ('extensions/signal_extension.yml ' );
120
- }
102
+ // @todo register MessageQueueCollector
121
103
122
- if ($ config ['extensions ' ]['reply_extension ' ]) {
123
- $ loader ->load ('extensions/reply_extension.yml ' );
124
- }
104
+ // if ($config['job']) {
105
+ // if (!class_exists(Job::class)) {
106
+ // throw new \LogicException('Seems "enqueue/job-queue" is not installed. Please fix this issue.');
107
+ // }
108
+ //
109
+ // $loader->load('job.yml');
110
+ // }
111
+ //
112
+ // if ($config['async_events']['enabled']) {
113
+ // if (false == class_exists(AsyncEventDispatcherExtension::class)) {
114
+ // throw new \LogicException('The "enqueue/async-event-dispatcher" package has to be installed.');
115
+ // }
116
+ //
117
+ // $extension = new AsyncEventDispatcherExtension();
118
+ // $extension->load([[
119
+ // 'context_service' => 'enqueue.transport.default.context',
120
+ // ]], $container);
121
+ // }
125
122
}
126
123
127
124
public function getConfiguration (array $ config , ContainerBuilder $ container ): Configuration
@@ -187,4 +184,113 @@ private function setupAutowiringForProcessors(ContainerBuilder $container, array
187
184
$ commandSubscriber ->addTag ('enqueue.command_subscriber ' , ['client ' => $ clientName ]);
188
185
}
189
186
}
187
+
188
+ private function loadDoctrinePingConnectionExtension (array $ config , ContainerBuilder $ container ): void
189
+ {
190
+ $ configNames = [];
191
+ foreach ($ config as $ name => $ modules ) {
192
+ if ($ modules ['extensions ' ]['doctrine_ping_connection_extension ' ]) {
193
+ $ configNames [] = $ name ;
194
+ }
195
+ }
196
+
197
+ if (false == $ configNames ) {
198
+ return ;
199
+ }
200
+
201
+ $ extension = $ container ->register ('enqueue.consumption.doctrine_ping_connection_extension ' , DoctrinePingConnectionExtension::class)
202
+ ->addArgument (new Reference ('doctrine ' ))
203
+ ;
204
+
205
+ foreach ($ configNames as $ name ) {
206
+ $ extension ->addTag ('enqueue.consumption_extension ' , ['client ' => $ name ]);
207
+ $ extension ->addTag ('enqueue.transport.consumption_extension ' , ['transport ' => $ name ]);
208
+ }
209
+ }
210
+
211
+ private function loadDoctrineClearIdentityMapExtension (array $ config , ContainerBuilder $ container ): void
212
+ {
213
+ $ configNames = [];
214
+ foreach ($ config as $ name => $ modules ) {
215
+ if ($ modules ['extensions ' ]['doctrine_clear_identity_map_extension ' ]) {
216
+ $ configNames [] = $ name ;
217
+ }
218
+ }
219
+
220
+ if (false == $ configNames ) {
221
+ return ;
222
+ }
223
+
224
+ $ extension = $ container ->register ('enqueue.consumption.doctrine_clear_identity_map_extension ' , DoctrineClearIdentityMapExtension::class)
225
+ ->addArgument (new Reference ('doctrine ' ))
226
+ ;
227
+
228
+ foreach ($ configNames as $ name ) {
229
+ $ extension ->addTag ('enqueue.consumption_extension ' , ['client ' => $ name ]);
230
+ $ extension ->addTag ('enqueue.transport.consumption_extension ' , ['transport ' => $ name ]);
231
+ }
232
+ }
233
+
234
+ private function loadSignalExtension (array $ config , ContainerBuilder $ container ): void
235
+ {
236
+ $ configNames = [];
237
+ foreach ($ config as $ name => $ modules ) {
238
+ if ($ modules ['extensions ' ]['signal_extension ' ]) {
239
+ $ configNames [] = $ name ;
240
+ }
241
+ }
242
+
243
+ if (false == $ configNames ) {
244
+ return ;
245
+ }
246
+
247
+ $ extension = $ container ->register ('enqueue.consumption.signal_extension ' , SignalExtension::class);
248
+
249
+ foreach ($ configNames as $ name ) {
250
+ $ extension ->addTag ('enqueue.consumption_extension ' , ['client ' => $ name ]);
251
+ $ extension ->addTag ('enqueue.transport.consumption_extension ' , ['transport ' => $ name ]);
252
+ }
253
+ }
254
+
255
+ private function loadReplyExtension (array $ config , ContainerBuilder $ container ): void
256
+ {
257
+ $ configNames = [];
258
+ foreach ($ config as $ name => $ modules ) {
259
+ if ($ modules ['extensions ' ]['reply_extension ' ]) {
260
+ $ configNames [] = $ name ;
261
+ }
262
+ }
263
+
264
+ if (false == $ configNames ) {
265
+ return ;
266
+ }
267
+
268
+ $ extension = $ container ->register ('enqueue.consumption.reply_extension ' , ReplyExtension::class);
269
+
270
+ foreach ($ configNames as $ name ) {
271
+ $ extension ->addTag ('enqueue.consumption_extension ' , ['client ' => $ name ]);
272
+ $ extension ->addTag ('enqueue.transport.consumption_extension ' , ['transport ' => $ name ]);
273
+ }
274
+ }
275
+
276
+ private function loadAsyncCommands (array $ config , ContainerBuilder $ container ): void
277
+ {
278
+ $ configNames = [];
279
+ foreach ($ config as $ name => $ modules ) {
280
+ if ($ modules ['async_commands ' ]['enabled ' ]) {
281
+ $ configNames [] = $ name ;
282
+ }
283
+ }
284
+
285
+ if (false == $ configNames ) {
286
+ return ;
287
+ }
288
+
289
+ if (false == class_exists (AsyncCommandExtension::class)) {
290
+ throw new \LogicException ('The "enqueue/async-command" package has to be installed. ' );
291
+ }
292
+
293
+ $ extension = new AsyncCommandExtension ();
294
+ $ extension ->load (['clients ' => $ configNames ], $ container );
295
+ }
190
296
}
0 commit comments