1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sludio\HelperBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
6
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
7
|
|
|
use Sludio\HelperBundle\Guzzle\DataCollector\GuzzleCollector; |
8
|
|
|
use GuzzleHttp\MessageFormatter; |
9
|
|
|
|
10
|
|
|
class Configuration implements ConfigurationInterface |
11
|
|
|
{ |
12
|
|
|
protected $alias; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Configuration constructor. |
16
|
|
|
*/ |
17
|
|
|
public function __construct($alias) |
18
|
|
|
{ |
19
|
|
|
$this->alias = $alias; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* {@inheritdoc} |
24
|
|
|
*/ |
25
|
|
|
public function getConfigTreeBuilder() |
26
|
|
|
{ |
27
|
|
|
$treeBuilder = new TreeBuilder(); |
28
|
|
|
$rootNode = $treeBuilder->root($this->alias); |
29
|
|
|
|
30
|
|
|
// @formatter:off |
31
|
|
|
$rootNode |
32
|
|
|
->children() |
33
|
|
|
->arrayNode('extensions') |
34
|
|
|
->addDefaultsIfNotSet() |
35
|
|
|
->children() |
36
|
|
|
->arrayNode('captcha') |
37
|
|
|
->addDefaultsIfNotSet() |
38
|
|
|
->canBeEnabled() |
39
|
|
|
->children() |
40
|
|
|
->arrayNode('clients') |
41
|
|
|
->prototype('array') |
42
|
|
|
->prototype('variable')->end() |
43
|
|
|
->end() |
44
|
|
|
->end() |
45
|
|
|
->end() |
46
|
|
|
->end() |
47
|
|
|
->arrayNode('guzzle') |
48
|
|
|
->addDefaultsIfNotSet() |
49
|
|
|
->canBeEnabled() |
50
|
|
|
->children() |
51
|
|
|
->arrayNode('profiler') |
52
|
|
|
->canBeEnabled() |
53
|
|
|
->children() |
54
|
|
|
->integerNode('max_body_size') |
55
|
|
|
->defaultValue(GuzzleCollector::MAX_BODY_SIZE) |
56
|
|
|
->end() |
57
|
|
|
->end() |
58
|
|
|
->end() |
59
|
|
|
->arrayNode('logger') |
60
|
|
|
->canBeEnabled() |
61
|
|
|
->children() |
62
|
|
|
->scalarNode('service')->defaultValue(null)->end() |
63
|
|
|
->scalarNode('format') |
64
|
|
|
->beforeNormalization() |
65
|
|
|
->ifInArray(['clf', 'debug', 'short']) |
66
|
|
|
->then(function($v) { |
67
|
|
|
return constant('GuzzleHttp\MessageFormatter::'.strtoupper($v)); |
68
|
|
|
}) |
69
|
|
|
->end() |
70
|
|
|
->defaultValue(MessageFormatter::CLF) |
71
|
|
|
->end() |
72
|
|
|
->scalarNode('level') |
73
|
|
|
->beforeNormalization() |
74
|
|
|
->ifInArray([ |
75
|
|
|
'emergency', 'alert', 'critical', 'error', |
76
|
|
|
'warning', 'notice', 'info', 'debug', |
77
|
|
|
]) |
78
|
|
|
->then(function($v) { |
79
|
|
|
return constant('Psr\Log\LogLevel::'.strtoupper($v)); |
80
|
|
|
}) |
81
|
|
|
->end() |
82
|
|
|
->defaultValue('debug') |
83
|
|
|
->end() |
84
|
|
|
->end() |
85
|
|
|
->end() |
86
|
|
|
->arrayNode('cache') |
87
|
|
|
->canBeEnabled() |
88
|
|
|
->validate() |
89
|
|
|
->ifTrue(function($v) { |
90
|
|
|
return $v['enabled'] && null === $v['adapter']; |
91
|
|
|
}) |
92
|
|
|
->thenInvalid('The \''.$this->alias.'.guzzle.cache.adapter\' key is mandatory if you enable the cache middleware') |
93
|
|
|
->end() |
94
|
|
|
->children() |
95
|
|
|
->scalarNode('adapter')->defaultNull()->end() |
96
|
|
|
->booleanNode('disabled')->defaultValue(null)->end() |
97
|
|
|
->end() |
98
|
|
|
->end() |
99
|
|
|
->arrayNode('clients') |
100
|
|
|
->useAttributeAsKey('name') |
101
|
|
|
->prototype('array') |
102
|
|
|
->children() |
103
|
|
|
->scalarNode('class') |
104
|
|
|
->defaultValue('GuzzleHttp\Client') |
105
|
|
|
->end() |
106
|
|
|
->booleanNode('lazy') |
107
|
|
|
->defaultFalse() |
108
|
|
|
->end() |
109
|
|
|
->variableNode('config')->end() |
110
|
|
|
->arrayNode('middleware') |
111
|
|
|
->prototype('scalar')->end() |
112
|
|
|
->end() |
113
|
|
|
->scalarNode('alias')->defaultNull()->end() |
114
|
|
|
->end() |
115
|
|
|
->end() |
116
|
|
|
->end() |
117
|
|
|
->arrayNode('mock') |
118
|
|
|
->canBeEnabled() |
119
|
|
|
->children() |
120
|
|
|
->scalarNode('storage_path')->isRequired()->end() |
121
|
|
|
->scalarNode('mode')->defaultValue('replay')->end() |
122
|
|
|
->arrayNode('request_headers_blacklist') |
123
|
|
|
->prototype('scalar')->end() |
124
|
|
|
->end() |
125
|
|
|
->arrayNode('response_headers_blacklist') |
126
|
|
|
->prototype('scalar')->end() |
127
|
|
|
->end() |
128
|
|
|
->end() |
129
|
|
|
->end() |
130
|
|
|
->end() |
131
|
|
|
->end() |
132
|
|
|
->arrayNode('lexik') |
133
|
|
|
->addDefaultsIfNotSet() |
134
|
|
|
->canBeEnabled() |
135
|
|
|
->children() |
136
|
|
|
->scalarNode('default_domain')->defaultValue('messages')->end() |
137
|
|
|
->arrayNode('default_selections') |
138
|
|
|
->addDefaultsIfNotSet() |
139
|
|
|
->children() |
140
|
|
|
->booleanNode('non_translated_only')->defaultValue(false)->end() |
141
|
|
|
->end() |
142
|
|
|
->end() |
143
|
|
|
->arrayNode('empty_prefixes') |
144
|
|
|
->defaultValue(['__', 'new_', '']) |
145
|
|
|
->prototype('array')->end() |
146
|
|
|
->end() |
147
|
|
|
->arrayNode('editable') |
148
|
|
|
->addDefaultsIfNotSet() |
149
|
|
|
->children() |
150
|
|
|
->scalarNode('type')->defaultValue('textarea')->end() |
151
|
|
|
->scalarNode('emptytext')->defaultValue('Empty')->end() |
152
|
|
|
->end() |
153
|
|
|
->end() |
154
|
|
|
->end() |
155
|
|
|
->end() |
156
|
|
|
->arrayNode('oauth') |
157
|
|
|
->addDefaultsIfNotSet() |
158
|
|
|
->canBeEnabled() |
159
|
|
|
->children() |
160
|
|
|
->arrayNode('clients') |
161
|
|
|
->prototype('array') |
162
|
|
|
->prototype('variable')->end() |
163
|
|
|
->end() |
164
|
|
|
->end() |
165
|
|
|
->arrayNode('custom_providers') |
166
|
|
|
->prototype('array') |
167
|
|
|
->prototype('variable')->end() |
168
|
|
|
->end() |
169
|
|
|
->end() |
170
|
|
|
->end() |
171
|
|
|
->end() |
172
|
|
|
->arrayNode('openid') |
173
|
|
|
->addDefaultsIfNotSet() |
174
|
|
|
->canBeEnabled() |
175
|
|
|
->children() |
176
|
|
|
->arrayNode('clients') |
177
|
|
|
->prototype('array') |
178
|
|
|
->prototype('variable')->end() |
179
|
|
|
->end() |
180
|
|
|
->end() |
181
|
|
|
->end() |
182
|
|
|
->end() |
183
|
|
|
->arrayNode('openidconnect') |
184
|
|
|
->addDefaultsIfNotSet() |
185
|
|
|
->canBeEnabled() |
186
|
|
|
->children() |
187
|
|
|
->arrayNode('clients') |
188
|
|
|
->prototype('array') |
189
|
|
|
->prototype('variable')->end() |
190
|
|
|
->end() |
191
|
|
|
->end() |
192
|
|
|
->end() |
193
|
|
|
->end() |
194
|
|
|
->arrayNode('pagination') |
195
|
|
|
->addDefaultsIfNotSet() |
196
|
|
|
->canBeEnabled() |
197
|
|
|
->children() |
198
|
|
|
->arrayNode('behaviour') |
199
|
|
|
->prototype('array') |
200
|
|
|
->prototype('variable')->end() |
201
|
|
|
->end() |
202
|
|
|
->end() |
203
|
|
|
->end() |
204
|
|
|
->end() |
205
|
|
|
->arrayNode('position') |
206
|
|
|
->addDefaultsIfNotSet() |
207
|
|
|
->canBeEnabled() |
208
|
|
|
->children() |
209
|
|
|
->arrayNode('field') |
210
|
|
|
->addDefaultsIfNotSet() |
211
|
|
|
->children() |
212
|
|
|
->scalarNode('default') |
213
|
|
|
->defaultValue('position') |
214
|
|
|
->end() |
215
|
|
|
->arrayNode('entities') |
216
|
|
|
->prototype('scalar')->end() |
217
|
|
|
->end() |
218
|
|
|
->end() |
219
|
|
|
->end() |
220
|
|
|
->end() |
221
|
|
|
->end() |
222
|
|
|
->arrayNode('script') |
223
|
|
|
->addDefaultsIfNotSet() |
224
|
|
|
->canBeEnabled() |
225
|
|
|
->children() |
226
|
|
|
->booleanNode('short_functions') |
227
|
|
|
->defaultValue(false) |
228
|
|
|
->end() |
229
|
|
|
->end() |
230
|
|
|
->end() |
231
|
|
|
->arrayNode('sitemap') |
232
|
|
|
->addDefaultsIfNotSet() |
233
|
|
|
->canBeEnabled() |
234
|
|
|
->children() |
235
|
|
|
->scalarNode('base_host') |
236
|
|
|
->defaultValue(null) |
237
|
|
|
->end() |
238
|
|
|
->scalarNode('limit') |
239
|
|
|
->defaultValue(null) |
240
|
|
|
->end() |
241
|
|
|
->enumNode('format') |
242
|
|
|
->values(['simple', 'rich']) |
243
|
|
|
->defaultValue('simple') |
244
|
|
|
->end() |
245
|
|
|
->enumNode('type') |
246
|
|
|
->values(['simple', 'gz']) |
247
|
|
|
->defaultValue('simple') |
248
|
|
|
->end() |
249
|
|
|
->end() |
250
|
|
|
->end() |
251
|
|
|
->arrayNode('translatable') |
252
|
|
|
->addDefaultsIfNotSet() |
253
|
|
|
->canBeEnabled() |
254
|
|
|
->children() |
255
|
|
|
->arrayNode('locales') |
256
|
|
|
->beforeNormalization() |
257
|
|
|
->ifString() |
258
|
|
|
->then(function($v) { |
259
|
|
|
return preg_split('/\s*,\s*/', $v); |
260
|
|
|
}) |
261
|
|
|
->end() |
262
|
|
|
->prototype('scalar')->end() |
263
|
|
|
->end() |
264
|
|
|
->scalarNode('default_locale') |
265
|
|
|
->defaultValue('en') |
266
|
|
|
->end() |
267
|
|
|
->scalarNode('template') |
268
|
|
|
->defaultValue('SludioHelperBundle:Translatable:translations.html.twig') |
269
|
|
|
->end() |
270
|
|
|
->scalarNode('table') |
271
|
|
|
->defaultValue('sludio_helper_translation') |
272
|
|
|
->end() |
273
|
|
|
->scalarNode('manager') |
274
|
|
|
->defaultValue('default') |
275
|
|
|
->end() |
276
|
|
|
->arrayNode('entities') |
277
|
|
|
->useAttributeAsKey('name') |
278
|
|
|
->prototype('array') |
279
|
|
|
->children() |
280
|
|
|
->scalarNode('entity') |
281
|
|
|
->defaultValue(null) |
282
|
|
|
->end() |
283
|
|
|
->arrayNode('fields') |
284
|
|
|
->useAttributeAsKey('name') |
285
|
|
|
->prototype('array') |
286
|
|
|
->children() |
287
|
|
|
->enumNode('class') |
288
|
|
|
->values(['titled', 'slugged', 'ck_item', null]) |
289
|
|
|
->defaultValue(null) |
290
|
|
|
->end() |
291
|
|
|
->enumNode('type') |
292
|
|
|
->values(['text', 'ckeditor']) |
293
|
|
|
->defaultValue('text') |
294
|
|
|
->end() |
295
|
|
|
->end() |
296
|
|
|
->end() |
297
|
|
|
->end() |
298
|
|
|
->end() |
299
|
|
|
->end() |
300
|
|
|
->end() |
301
|
|
|
->end() |
302
|
|
|
->end() |
303
|
|
|
->end() |
304
|
|
|
->end() |
305
|
|
|
->arrayNode('other') |
306
|
|
|
->addDefaultsIfNotSet() |
307
|
|
|
->children() |
308
|
|
|
->arrayNode('logger') |
309
|
|
|
->addDefaultsIfNotSet() |
310
|
|
|
->children() |
311
|
|
|
->scalarNode('class') |
312
|
|
|
->defaultValue('Sludio\HelperBundle\Logger\SludioLogger') |
313
|
|
|
->end() |
314
|
|
|
->end() |
315
|
|
|
->end() |
316
|
|
|
->arrayNode('redis') |
317
|
|
|
->addDefaultsIfNotSet() |
318
|
|
|
->children() |
319
|
|
|
->scalarNode('translation') |
320
|
|
|
->defaultValue('session') |
321
|
|
|
->end() |
322
|
|
|
->scalarNode('guzzle') |
323
|
|
|
->defaultValue('session') |
324
|
|
|
->end() |
325
|
|
|
->end() |
326
|
|
|
->end() |
327
|
|
|
->arrayNode('entity') |
328
|
|
|
->addDefaultsIfNotSet() |
329
|
|
|
->children() |
330
|
|
|
->scalarNode('manager') |
331
|
|
|
->defaultValue('default') |
332
|
|
|
->end() |
333
|
|
|
->end() |
334
|
|
|
->end() |
335
|
|
|
->scalarNode('locale') |
336
|
|
|
->defaultValue('en') |
337
|
|
|
->end() |
338
|
|
|
->end() |
339
|
|
|
->end() |
340
|
|
|
->end() |
341
|
|
|
; |
342
|
|
|
// @formatter:on |
343
|
|
|
|
344
|
|
|
return $treeBuilder; |
345
|
|
|
} |
346
|
|
|
} |
347
|
|
|
|