|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Dtc\QueueBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
trait RabbitMQConfiguration |
|
8
|
|
|
{ |
|
9
|
10 |
|
protected function addRabbitMqOptions() |
|
10
|
|
|
{ |
|
11
|
10 |
|
$treeBuilder = new TreeBuilder('options'); |
|
12
|
|
|
|
|
13
|
10 |
|
if (method_exists($treeBuilder, 'getRootNode')) { |
|
14
|
10 |
|
$rootNode = $treeBuilder->getRootNode(); |
|
15
|
|
|
} else { |
|
16
|
|
|
// BC layer for symfony/config 4.1 and older |
|
17
|
|
|
$rootNode = $treeBuilder->root('options'); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
$rootNode |
|
21
|
10 |
|
->children() |
|
22
|
10 |
|
->scalarNode('insist')->end() |
|
23
|
10 |
|
->scalarNode('login_method')->end() |
|
24
|
10 |
|
->scalarNode('login_response')->end() |
|
25
|
10 |
|
->scalarNode('locale')->end() |
|
26
|
10 |
|
->floatNode('connection_timeout')->end() |
|
27
|
10 |
|
->floatNode('read_write_timeout')->end() |
|
28
|
10 |
|
->booleanNode('keepalive')->end() |
|
29
|
10 |
|
->integerNode('heartbeat')->end() |
|
30
|
10 |
|
->end(); |
|
31
|
|
|
|
|
32
|
10 |
|
return $rootNode; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
10 |
|
protected function addRabbitMqSslOptions() |
|
36
|
|
|
{ |
|
37
|
10 |
|
$treeBuilder = new TreeBuilder('ssl_options'); |
|
38
|
|
|
|
|
39
|
10 |
|
if (method_exists($treeBuilder, 'getRootNode')) { |
|
40
|
10 |
|
$rootNode = $treeBuilder->getRootNode(); |
|
41
|
|
|
} else { |
|
42
|
|
|
// BC layer for symfony/config 4.1 and older |
|
43
|
|
|
$rootNode = $treeBuilder->root('ssl_options'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$rootNode |
|
47
|
10 |
|
->prototype('variable')->end() |
|
48
|
10 |
|
->validate() |
|
49
|
10 |
|
->ifTrue(function ($node) { |
|
50
|
1 |
|
if (!is_array($node)) { |
|
51
|
|
|
return true; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
1 |
|
return $this->validateNode($node); |
|
55
|
10 |
|
}) |
|
56
|
10 |
|
->thenInvalid('Must be key-value pairs') |
|
57
|
10 |
|
->end(); |
|
58
|
|
|
|
|
59
|
10 |
|
return $rootNode; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
1 |
|
private function validateNode(array $node) |
|
63
|
|
|
{ |
|
64
|
1 |
|
foreach ($node as $key => $value) { |
|
65
|
1 |
|
if (is_array($value)) { |
|
66
|
1 |
|
if ($this->validateArray($key, $value)) { |
|
67
|
1 |
|
return true; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
1 |
|
return false; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
1 |
|
private function validateArray($key, $value) |
|
76
|
|
|
{ |
|
77
|
1 |
|
if ('peer_fingerprint' !== $key) { |
|
78
|
1 |
|
return true; |
|
79
|
|
|
} |
|
80
|
1 |
|
foreach ($value as $key1 => $value1) { |
|
81
|
1 |
|
if (!is_string($key1) || !is_string($value1)) { |
|
82
|
|
|
return true; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
1 |
|
return false; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
10 |
|
protected function addRabbitMqExchange() |
|
90
|
|
|
{ |
|
91
|
10 |
|
$treeBuilder = new TreeBuilder('exchange_args'); |
|
92
|
|
|
|
|
93
|
10 |
|
if (method_exists($treeBuilder, 'getRootNode')) { |
|
94
|
10 |
|
$rootNode = $treeBuilder->getRootNode(); |
|
95
|
|
|
} else { |
|
96
|
|
|
// BC layer for symfony/config 4.1 and older |
|
97
|
|
|
$rootNode = $treeBuilder->root('exchange_args'); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
$rootNode |
|
101
|
10 |
|
->addDefaultsIfNotSet() |
|
102
|
10 |
|
->children() |
|
103
|
10 |
|
->scalarNode('exchange')->defaultValue('dtc_queue_exchange')->end() |
|
104
|
10 |
|
->booleanNode('type')->defaultValue('direct')->end() |
|
105
|
10 |
|
->booleanNode('passive')->defaultFalse()->end() |
|
106
|
10 |
|
->booleanNode('durable')->defaultTrue()->end() |
|
107
|
10 |
|
->booleanNode('auto_delete')->defaultFalse()->end() |
|
108
|
10 |
|
->end(); |
|
109
|
|
|
|
|
110
|
10 |
|
return $rootNode; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
10 |
|
protected function addRabbitMqArgs() |
|
114
|
|
|
{ |
|
115
|
10 |
|
$treeBuilder = new TreeBuilder('queue_args'); |
|
116
|
|
|
|
|
117
|
10 |
|
if (method_exists($treeBuilder, 'getRootNode')) { |
|
118
|
10 |
|
$rootNode = $treeBuilder->getRootNode(); |
|
119
|
|
|
} else { |
|
120
|
|
|
// BC layer for symfony/config 4.1 and older |
|
121
|
|
|
$rootNode = $treeBuilder->root('queue_args'); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
$rootNode |
|
125
|
10 |
|
->addDefaultsIfNotSet() |
|
126
|
10 |
|
->children() |
|
127
|
10 |
|
->scalarNode('queue')->defaultValue('dtc_queue')->end() |
|
128
|
10 |
|
->booleanNode('passive')->defaultFalse()->end() |
|
129
|
10 |
|
->booleanNode('durable')->defaultTrue()->end() |
|
130
|
10 |
|
->booleanNode('exclusive')->defaultFalse()->end() |
|
131
|
10 |
|
->booleanNode('auto_delete')->defaultFalse()->end() |
|
132
|
10 |
|
->end(); |
|
133
|
|
|
|
|
134
|
10 |
|
return $rootNode; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
10 |
|
protected function addRabbitMq() |
|
138
|
|
|
{ |
|
139
|
10 |
|
$treeBuilder = new TreeBuilder('rabbit_mq'); |
|
140
|
|
|
|
|
141
|
10 |
|
if (method_exists($treeBuilder, 'getRootNode')) { |
|
142
|
10 |
|
$rootNode = $treeBuilder->getRootNode(); |
|
143
|
|
|
} else { |
|
144
|
|
|
// BC layer for symfony/config 4.1 and older |
|
145
|
|
|
$rootNode = $treeBuilder->root('rabbit_mq'); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
$rootNode |
|
149
|
10 |
|
->children() |
|
150
|
10 |
|
->scalarNode('host')->end() |
|
151
|
10 |
|
->scalarNode('port')->end() |
|
152
|
10 |
|
->scalarNode('user')->end() |
|
153
|
10 |
|
->scalarNode('password')->end() |
|
154
|
10 |
|
->scalarNode('vhost')->defaultValue('/')->end() |
|
155
|
10 |
|
->booleanNode('ssl')->defaultFalse()->end() |
|
156
|
10 |
|
->append($this->addRabbitMqOptions()) |
|
157
|
10 |
|
->append($this->addRabbitMqSslOptions()) |
|
158
|
10 |
|
->append($this->addRabbitMqArgs()) |
|
159
|
10 |
|
->append($this->addRabbitMqExchange()) |
|
160
|
10 |
|
->end() |
|
161
|
10 |
|
->validate()->always(function ($node) { |
|
162
|
1 |
|
if (empty($node['ssl_options'])) { |
|
163
|
1 |
|
unset($node['ssl_options']); |
|
164
|
|
|
} |
|
165
|
1 |
|
if (empty($node['options'])) { |
|
166
|
1 |
|
unset($node['options']); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
1 |
|
return $node; |
|
170
|
10 |
|
})->end() |
|
171
|
10 |
|
->validate()->ifTrue(function ($node) { |
|
172
|
1 |
|
if (isset($node['ssl_options']) && !$node['ssl']) { |
|
173
|
1 |
|
return true; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
1 |
|
return false; |
|
177
|
10 |
|
})->thenInvalid('ssl must be true in order to set ssl_options')->end() |
|
178
|
10 |
|
->end(); |
|
179
|
|
|
|
|
180
|
10 |
|
return $rootNode; |
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths