1
+ <?php
2
+
3
+ namespace Queue \App ;
4
+
5
+ use Laminas \ServiceManager \Factory \InvokableFactory ;
6
+ use Netglue \PsrContainer \Messenger \Container \MessageBusStaticFactory ;
7
+ use Netglue \PsrContainer \Messenger \Container \Middleware \BusNameStampMiddlewareStaticFactory ;
8
+ use Netglue \PsrContainer \Messenger \Container \Middleware \MessageHandlerMiddlewareStaticFactory ;
9
+ use Netglue \PsrContainer \Messenger \Container \Middleware \MessageSenderMiddlewareStaticFactory ;
10
+ use Netglue \PsrContainer \Messenger \HandlerLocator \OneToManyFqcnContainerHandlerLocator ;
11
+ use Queue \App \Message \ExampleMessage ;
12
+ use Queue \App \Message \ExampleMessageHandler ;
13
+ use Queue \App \Message \ExampleMessageHandlerFactory ;
14
+ use Symfony \Component \Messenger \MessageBusInterface ;
15
+
16
+ class ConfigProvider
17
+ {
18
+ public function __invoke ()
19
+ {
20
+ return [
21
+ "dependencies " => $ this ->getDependencies (),
22
+ 'symfony ' => [
23
+ 'messenger ' => [
24
+ 'buses ' => $ this ->busConfig (),
25
+ ],
26
+ ],
27
+ ];
28
+ }
29
+
30
+
31
+ private function getDependencies ()
32
+ {
33
+ return [
34
+ "factories " => [
35
+ "message_bus " => [MessageBusStaticFactory::class, "message_bus " ],
36
+ "message_bus_stamp_middleware " => [BusNameStampMiddlewareStaticFactory::class, "message_bus " ],
37
+ "message_bus_sender_middleware " => [MessageSenderMiddlewareStaticFactory::class, "message_bus " ],
38
+ "message_bus_handler_middleware " => [MessageHandlerMiddlewareStaticFactory::class, "message_bus " ],
39
+ ExampleMessageHandler::class => ExampleMessageHandlerFactory::class
40
+ ],
41
+ "aliases " => [
42
+ MessageBusInterface::class => "message_bus "
43
+ ]
44
+ ];
45
+ }
46
+
47
+ private function busConfig ()
48
+ {
49
+ return [
50
+ "message_bus " => [
51
+ 'allows_zero_handlers ' => false , // Means that it's an error if no handlers are defined for a given message
52
+
53
+ /**
54
+ * Each bus needs middleware to do anything useful.
55
+ *
56
+ * Below is a minimal configuration to handle messages
57
+ */
58
+ 'middleware ' => [
59
+ // … Middleware that inspects the message before it has been sent to a transport would go here.
60
+ "message_bus_stamp_middleware " ,
61
+ 'message_bus_sender_middleware ' , // Sends messages via a transport if configured.
62
+ 'message_bus_handler_middleware ' , // Executes the handlers configured for the message
63
+ ],
64
+
65
+ /**
66
+ * Map messages to one or more handlers:
67
+ *
68
+ * Two locators are shipped, 1 message type to 1 handler and 1 message type to many handlers.
69
+ * Both locators operate on the basis that handlers are available in the container.
70
+ *
71
+ */
72
+ 'handler_locator ' => OneToManyFqcnContainerHandlerLocator::class,
73
+ 'handlers ' => [
74
+ ExampleMessage::class => [ExampleMessageHandler::class],
75
+ ],
76
+
77
+ /**
78
+ * Routes define which transport(s) that messages dispatched on this bus should be sent with.
79
+ *
80
+ * The * wildcard applies to all messages.
81
+ * The transport for each route must be an array of one or more transport identifiers. Each transport
82
+ * is retrieved from the DI container by this value.
83
+ *
84
+ * An empty routes definition would mean that messages would be handled immediately and synchronously,
85
+ * i.e. no transport would be used.
86
+ *
87
+ * Route specific messages to specific transports by using the message name as the key.
88
+ */
89
+ 'routes ' => [
90
+ ExampleMessage::class => ["redis " ],
91
+ ],
92
+ ]
93
+ ];
94
+ }
95
+ }
0 commit comments