1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bdf\QueueBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
6
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
7
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Configuration. |
11
|
|
|
*/ |
12
|
|
|
class Configuration implements ConfigurationInterface |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var bool |
16
|
|
|
*/ |
17
|
|
|
private $debug; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param bool $debug Whether to use the debug mode |
21
|
|
|
*/ |
22
|
11 |
|
public function __construct($debug = false) |
23
|
|
|
{ |
24
|
11 |
|
$this->debug = (bool) $debug; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* {@inheritDoc} |
29
|
|
|
*/ |
30
|
11 |
|
public function getConfigTreeBuilder() |
31
|
|
|
{ |
32
|
11 |
|
$treeBuilder = new TreeBuilder('bdf_queue'); |
33
|
11 |
|
$treeBuilder->getRootNode() |
34
|
11 |
|
->children() |
35
|
11 |
|
->scalarNode('default_connection')->defaultNull()->end() |
36
|
11 |
|
->scalarNode('default_serializer')->defaultValue('bdf')->end() |
37
|
11 |
|
->scalarNode('failer') |
38
|
11 |
|
->info('A DSN with failer configuration; Format: [memory|prime]://{connection}/{table}') |
39
|
11 |
|
->defaultValue('memory:') |
40
|
11 |
|
->cannotBeEmpty() |
41
|
11 |
|
->end() |
42
|
11 |
|
->append($this->getConnectionsNode()) |
43
|
11 |
|
->append($this->getDestinationsNode()) |
44
|
11 |
|
->end() |
45
|
11 |
|
; |
46
|
|
|
|
47
|
11 |
|
return $treeBuilder; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return NodeDefinition |
52
|
|
|
*/ |
53
|
11 |
|
private function getConnectionsNode() |
54
|
|
|
{ |
55
|
11 |
|
$root = (new TreeBuilder('connections'))->getRootNode(); |
56
|
11 |
|
$root |
57
|
11 |
|
->requiresAtLeastOneElement() |
|
|
|
|
58
|
11 |
|
->useAttributeAsKey('name') |
59
|
11 |
|
->arrayPrototype() |
60
|
11 |
|
->isRequired() |
61
|
11 |
|
->beforeNormalization() |
62
|
11 |
|
->ifString() |
63
|
11 |
|
->then(static function ($v) { |
64
|
|
|
return ['url' => $v]; |
65
|
11 |
|
}) |
66
|
11 |
|
->end() |
67
|
11 |
|
->children() |
68
|
11 |
|
->scalarNode('url') |
69
|
11 |
|
->info('A URL with connection information; any parameter value parsed from this string will override explicitly set parameters. Format: {driver}+{vendor}://{user}:{password}@{host}:{port}/{queue}?{option}=value') |
70
|
11 |
|
->defaultNull() |
71
|
11 |
|
->end() |
72
|
11 |
|
->scalarNode('driver')->defaultNull()->end() |
73
|
11 |
|
->scalarNode('vendor')->defaultNull()->end() |
74
|
11 |
|
->scalarNode('queue')->defaultNull()->end() |
75
|
11 |
|
->scalarNode('host')->defaultNull()->end() |
76
|
11 |
|
->scalarNode('port')->defaultNull()->end() |
77
|
11 |
|
->scalarNode('user')->defaultNull()->end() |
78
|
11 |
|
->scalarNode('password')->defaultNull()->end() |
79
|
11 |
|
->arrayNode('serializer') |
80
|
11 |
|
->addDefaultsIfNotSet() |
81
|
11 |
|
->beforeNormalization() |
82
|
11 |
|
->ifString() |
83
|
11 |
|
->then(static function ($v) { |
84
|
1 |
|
return ['id' => $v]; |
85
|
11 |
|
}) |
86
|
11 |
|
->end() |
87
|
11 |
|
->children() |
88
|
11 |
|
->scalarNode('id') |
89
|
11 |
|
->info('The serializer ID. This ID will be prefix by "bdf_queue.serializer". Defined values: native, bdf, bdf_json.') |
90
|
11 |
|
->end() |
91
|
11 |
|
->scalarNode('service') |
92
|
11 |
|
->info('The serializer service ID.') |
93
|
11 |
|
->end() |
94
|
11 |
|
->end() |
95
|
11 |
|
->end() |
96
|
11 |
|
->arrayNode('options') |
97
|
11 |
|
->useAttributeAsKey('key') |
98
|
11 |
|
->variablePrototype()->end() |
99
|
11 |
|
->end() |
100
|
11 |
|
->scalarNode('connection_factory') |
101
|
11 |
|
->defaultNull() |
102
|
11 |
|
->end() |
103
|
11 |
|
->end(); |
104
|
|
|
|
105
|
11 |
|
return $root; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return NodeDefinition |
110
|
|
|
*/ |
111
|
11 |
|
private function getDestinationsNode() |
112
|
|
|
{ |
113
|
11 |
|
$root = (new TreeBuilder('destinations'))->getRootNode(); |
114
|
11 |
|
$root |
115
|
11 |
|
->requiresAtLeastOneElement() |
116
|
11 |
|
->useAttributeAsKey('name') |
117
|
11 |
|
->arrayPrototype() |
118
|
11 |
|
->isRequired() |
119
|
11 |
|
->beforeNormalization() |
120
|
11 |
|
->ifString() |
121
|
11 |
|
->then(static function ($v) { |
122
|
|
|
return ['url' => $v]; |
123
|
11 |
|
}) |
124
|
11 |
|
->end() |
125
|
11 |
|
->children() |
126
|
11 |
|
->scalarNode('url') |
127
|
11 |
|
->info('A URL with destination information; Format: [queue|queues|topic]://{connection}/{queue}') |
128
|
11 |
|
->cannotBeEmpty() |
129
|
11 |
|
->end() |
130
|
11 |
|
->arrayNode('consumer') |
131
|
11 |
|
->children() |
132
|
11 |
|
->scalarNode('handler') |
133
|
11 |
|
->info('Set unique handler as outlet receiver') |
134
|
11 |
|
->defaultNull()->end() |
135
|
11 |
|
->scalarNode('retry') |
136
|
11 |
|
->info('Retry failed jobs (i.e. throwing an exception)') |
137
|
11 |
|
->defaultNull()->end() |
138
|
11 |
|
->scalarNode('max') |
139
|
11 |
|
->info('Limit the number of received message. When the limit is reached, the consumer is stopped') |
140
|
11 |
|
->defaultNull()->end() |
141
|
11 |
|
->scalarNode('limit') |
142
|
11 |
|
->info('Limit the received message rate') |
143
|
11 |
|
->defaultNull()->end() |
144
|
11 |
|
->scalarNode('memory') |
145
|
11 |
|
->info('Limit the total memory usage of the current runtime in bytes. When the limit is reached, the consumer is stopped') |
146
|
11 |
|
->defaultNull()->end() |
147
|
11 |
|
->booleanNode('save') |
148
|
11 |
|
->info('Store the failed messages') |
149
|
11 |
|
->defaultNull()->end() |
150
|
11 |
|
->booleanNode('no_failure') |
151
|
11 |
|
->info('Catch all exceptions to ensure that the consumer will no crash (and will silently fail)') |
152
|
11 |
|
->defaultNull()->end() |
153
|
11 |
|
->booleanNode('no_reset') |
154
|
11 |
|
->info('Disable the reset of services between messages.') |
155
|
11 |
|
->defaultNull()->end() |
156
|
11 |
|
->booleanNode('stop_when_empty') |
157
|
11 |
|
->info('Stops consumption when the destination is empty (i.e. no messages are received during the waiting duration)') |
158
|
11 |
|
->defaultNull()->end() |
159
|
11 |
|
->booleanNode('auto_handle') |
160
|
11 |
|
->info('Set auto discover as outlet receiver. The message should contain target hint.') |
161
|
11 |
|
->defaultNull()->end() |
162
|
11 |
|
->arrayNode('middlewares') |
163
|
11 |
|
->useAttributeAsKey('name') |
164
|
11 |
|
->variablePrototype()->end() |
165
|
11 |
|
->end() |
166
|
11 |
|
->end() |
167
|
11 |
|
->end() |
168
|
11 |
|
->end(); |
169
|
|
|
|
170
|
11 |
|
return $root; |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|