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