1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the FOSElasticaBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace FOS\ElasticaBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
15
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
16
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
17
|
|
|
|
18
|
|
|
class Configuration implements ConfigurationInterface |
19
|
|
|
{ |
20
|
|
|
private const SUPPORTED_DRIVERS = ['orm', 'mongodb', 'phpcr']; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* If the kernel is running in debug mode. |
24
|
|
|
* |
25
|
|
|
* @var bool |
26
|
|
|
*/ |
27
|
|
|
private $debug; |
28
|
|
|
|
29
|
34 |
|
public function __construct($debug) |
30
|
|
|
{ |
31
|
34 |
|
$this->debug = $debug; |
32
|
34 |
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Generates the configuration tree. |
36
|
|
|
* |
37
|
|
|
* @return TreeBuilder |
38
|
|
|
*/ |
39
|
34 |
|
public function getConfigTreeBuilder() |
40
|
|
|
{ |
41
|
34 |
|
$treeBuilder = new TreeBuilder('fos_elastica'); |
42
|
34 |
|
$rootNode = $treeBuilder->getRootNode(); |
43
|
|
|
|
44
|
34 |
|
$this->addClientsSection($rootNode); |
|
|
|
|
45
|
34 |
|
$this->addIndexesSection($rootNode); |
|
|
|
|
46
|
34 |
|
$this->addIndexTemplatesSection($rootNode); |
|
|
|
|
47
|
|
|
|
48
|
|
|
$rootNode |
49
|
34 |
|
->children() |
50
|
34 |
|
->scalarNode('default_client') |
51
|
34 |
|
->info('Defaults to the first client defined') |
52
|
34 |
|
->end() |
53
|
34 |
|
->scalarNode('default_index') |
54
|
34 |
|
->info('Defaults to the first index defined') |
55
|
34 |
|
->end() |
56
|
34 |
|
->scalarNode('default_manager')->defaultValue('orm')->end() |
57
|
34 |
|
->arrayNode('serializer') |
58
|
34 |
|
->treatNullLike([]) |
59
|
34 |
|
->children() |
60
|
34 |
|
->scalarNode('callback_class')->defaultValue('FOS\ElasticaBundle\Serializer\Callback')->end() |
61
|
34 |
|
->scalarNode('serializer')->defaultValue('serializer')->end() |
62
|
34 |
|
->end() |
63
|
34 |
|
->end() |
64
|
34 |
|
->end() |
65
|
|
|
; |
66
|
|
|
|
67
|
34 |
|
return $treeBuilder; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Returns the array node used for "dynamic_templates". |
72
|
|
|
*/ |
73
|
34 |
|
private function getDynamicTemplateNode() |
74
|
|
|
{ |
75
|
34 |
|
$node = $this->createTreeBuilderNode('dynamic_templates'); |
76
|
|
|
|
77
|
|
|
$node |
78
|
34 |
|
->prototype('array') |
79
|
34 |
|
->prototype('array') |
80
|
34 |
|
->children() |
81
|
34 |
|
->scalarNode('match')->end() |
82
|
34 |
|
->scalarNode('unmatch')->end() |
83
|
34 |
|
->scalarNode('match_mapping_type')->end() |
84
|
34 |
|
->scalarNode('path_match')->end() |
85
|
34 |
|
->scalarNode('path_unmatch')->end() |
86
|
34 |
|
->scalarNode('match_pattern')->end() |
87
|
34 |
|
->arrayNode('mapping') |
88
|
34 |
|
->prototype('variable') |
89
|
34 |
|
->treatNullLike([]) |
90
|
34 |
|
->end() |
91
|
34 |
|
->end() |
92
|
34 |
|
->end() |
93
|
34 |
|
->end() |
94
|
34 |
|
->end() |
95
|
|
|
; |
96
|
|
|
|
97
|
34 |
|
return $node; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Returns the array node used for "types". |
102
|
|
|
*/ |
103
|
|
|
private function getTypesNode() |
|
|
|
|
104
|
|
|
{ |
105
|
|
|
$node = $this->createTreeBuilderNode('types'); |
106
|
|
|
|
107
|
|
|
$node |
|
|
|
|
108
|
|
|
->useAttributeAsKey('name') |
109
|
|
|
->prototype('array') |
110
|
|
|
->treatNullLike([]) |
111
|
|
|
->beforeNormalization() |
112
|
|
|
->ifNull() |
113
|
|
|
->thenEmptyArray() |
114
|
|
|
->end() |
115
|
|
|
// Support multiple dynamic_template formats to match the old bundle style |
116
|
|
|
// and the way ElasticSearch expects them |
117
|
|
|
->beforeNormalization() |
118
|
|
|
->ifTrue(function ($v) { |
119
|
|
|
return isset($v['dynamic_templates']); |
120
|
|
|
}) |
121
|
|
|
->then(function ($v) { |
122
|
|
|
$dt = []; |
123
|
|
|
foreach ($v['dynamic_templates'] as $key => $type) { |
124
|
|
|
if (is_int($key)) { |
125
|
|
|
$dt[] = $type; |
126
|
|
|
} else { |
127
|
|
|
$dt[][$key] = $type; |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
$v['dynamic_templates'] = $dt; |
132
|
|
|
|
133
|
|
|
return $v; |
134
|
|
|
}) |
135
|
|
|
->end() |
136
|
|
|
->children() |
137
|
|
|
->booleanNode('date_detection')->end() |
138
|
|
|
->arrayNode('dynamic_date_formats')->prototype('scalar')->end()->end() |
139
|
|
|
->scalarNode('analyzer')->end() |
140
|
|
|
->booleanNode('numeric_detection')->end() |
141
|
|
|
->scalarNode('dynamic')->end() |
142
|
|
|
->end() |
143
|
|
|
->append($this->getIdNode()) |
144
|
|
|
->append($this->getPropertiesNode()) |
145
|
|
|
->append($this->getDynamicTemplateNode()) |
146
|
|
|
->append($this->getSourceNode()) |
147
|
|
|
->append($this->getRoutingNode()) |
148
|
|
|
->end() |
149
|
|
|
; |
150
|
|
|
|
151
|
|
|
return $node; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Returns the array node used for "properties". |
156
|
|
|
*/ |
157
|
34 |
|
private function getPropertiesNode() |
158
|
|
|
{ |
159
|
34 |
|
$node = $this->createTreeBuilderNode('properties'); |
160
|
|
|
|
161
|
|
|
$node |
|
|
|
|
162
|
34 |
|
->useAttributeAsKey('name') |
163
|
34 |
|
->prototype('variable') |
164
|
34 |
|
->treatNullLike([]); |
165
|
|
|
|
166
|
34 |
|
return $node; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Returns the array node used for "_id". |
171
|
|
|
*/ |
172
|
34 |
|
private function getIdNode() |
173
|
|
|
{ |
174
|
34 |
|
$node = $this->createTreeBuilderNode('_id'); |
175
|
|
|
|
176
|
|
|
$node |
177
|
34 |
|
->children() |
178
|
34 |
|
->scalarNode('path')->end() |
179
|
34 |
|
->end() |
180
|
|
|
; |
181
|
|
|
|
182
|
34 |
|
return $node; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Returns the array node used for "_source". |
187
|
|
|
*/ |
188
|
34 |
|
private function getSourceNode() |
189
|
|
|
{ |
190
|
34 |
|
$node = $this->createTreeBuilderNode('_source'); |
191
|
|
|
|
192
|
|
|
$node |
193
|
34 |
|
->children() |
194
|
34 |
|
->arrayNode('excludes') |
195
|
34 |
|
->useAttributeAsKey('name') |
196
|
34 |
|
->prototype('scalar')->end() |
197
|
34 |
|
->end() |
198
|
34 |
|
->arrayNode('includes') |
199
|
34 |
|
->useAttributeAsKey('name') |
200
|
34 |
|
->prototype('scalar')->end() |
201
|
34 |
|
->end() |
202
|
34 |
|
->scalarNode('compress')->end() |
203
|
34 |
|
->scalarNode('compress_threshold')->end() |
204
|
34 |
|
->scalarNode('enabled')->defaultTrue()->end() |
205
|
34 |
|
->end() |
206
|
|
|
; |
207
|
|
|
|
208
|
34 |
|
return $node; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Returns the array node used for "_routing". |
213
|
|
|
*/ |
214
|
34 |
|
private function getRoutingNode() |
215
|
|
|
{ |
216
|
34 |
|
$node = $this->createTreeBuilderNode('_routing'); |
217
|
|
|
|
218
|
|
|
$node |
219
|
34 |
|
->children() |
220
|
34 |
|
->scalarNode('required')->end() |
221
|
34 |
|
->scalarNode('path')->end() |
222
|
34 |
|
->end() |
223
|
|
|
; |
224
|
|
|
|
225
|
34 |
|
return $node; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* @return ArrayNodeDefinition|\Symfony\Component\Config\Definition\Builder\NodeDefinition |
230
|
|
|
*/ |
231
|
34 |
|
private function getPersistenceNode() |
232
|
|
|
{ |
233
|
34 |
|
$node = $this->createTreeBuilderNode('persistence'); |
234
|
|
|
|
235
|
|
|
$node |
236
|
34 |
|
->validate() |
237
|
|
|
->ifTrue(function ($v) { |
238
|
16 |
|
return isset($v['driver']) && 'orm' !== $v['driver'] && !empty($v['elastica_to_model_transformer']['hints']); |
239
|
34 |
|
}) |
240
|
34 |
|
->thenInvalid('Hints are only supported by the "orm" driver') |
241
|
34 |
|
->end() |
242
|
34 |
|
->children() |
243
|
34 |
|
->scalarNode('driver') |
244
|
34 |
|
->defaultValue('orm') |
245
|
34 |
|
->validate() |
246
|
34 |
|
->ifNotInArray(self::SUPPORTED_DRIVERS) |
247
|
34 |
|
->thenInvalid('The driver %s is not supported. Please choose one of '.json_encode(self::SUPPORTED_DRIVERS)) |
248
|
34 |
|
->end() |
249
|
34 |
|
->end() |
250
|
34 |
|
->scalarNode('model')->defaultValue(null)->end() |
251
|
34 |
|
->scalarNode('repository')->end() |
252
|
34 |
|
->scalarNode('identifier')->defaultValue('id')->end() |
253
|
34 |
|
->arrayNode('provider') |
254
|
34 |
|
->addDefaultsIfNotSet() |
255
|
34 |
|
->children() |
256
|
34 |
|
->scalarNode('batch_size')->defaultValue(100)->end() |
257
|
34 |
|
->scalarNode('clear_object_manager')->defaultTrue()->end() |
258
|
34 |
|
->scalarNode('debug_logging') |
259
|
34 |
|
->defaultValue($this->debug) |
260
|
34 |
|
->treatNullLike(true) |
261
|
34 |
|
->end() |
262
|
34 |
|
->scalarNode('query_builder_method')->defaultValue('createQueryBuilder')->end() |
263
|
34 |
|
->scalarNode('service')->end() |
264
|
34 |
|
->end() |
265
|
34 |
|
->end() |
266
|
34 |
|
->arrayNode('listener') |
267
|
34 |
|
->addDefaultsIfNotSet() |
268
|
34 |
|
->children() |
269
|
34 |
|
->booleanNode('enabled')->defaultTrue()->end() |
270
|
34 |
|
->scalarNode('insert')->defaultTrue()->end() |
271
|
34 |
|
->scalarNode('update')->defaultTrue()->end() |
272
|
34 |
|
->scalarNode('delete')->defaultTrue()->end() |
273
|
34 |
|
->scalarNode('flush')->defaultTrue()->end() |
274
|
34 |
|
->booleanNode('defer')->defaultFalse()->end() |
275
|
34 |
|
->scalarNode('logger') |
276
|
34 |
|
->defaultFalse() |
277
|
34 |
|
->treatNullLike('fos_elastica.logger') |
278
|
34 |
|
->treatTrueLike('fos_elastica.logger') |
279
|
34 |
|
->end() |
280
|
34 |
|
->scalarNode('service')->end() |
281
|
34 |
|
->end() |
282
|
34 |
|
->end() |
283
|
34 |
|
->arrayNode('finder') |
284
|
34 |
|
->addDefaultsIfNotSet() |
285
|
34 |
|
->children() |
286
|
34 |
|
->scalarNode('service')->end() |
287
|
34 |
|
->end() |
288
|
34 |
|
->end() |
289
|
34 |
|
->arrayNode('elastica_to_model_transformer') |
290
|
34 |
|
->addDefaultsIfNotSet() |
291
|
34 |
|
->children() |
292
|
34 |
|
->arrayNode('hints') |
293
|
34 |
|
->prototype('array') |
294
|
34 |
|
->children() |
295
|
34 |
|
->scalarNode('name')->end() |
296
|
34 |
|
->scalarNode('value')->end() |
297
|
34 |
|
->end() |
298
|
34 |
|
->end() |
299
|
34 |
|
->end() |
300
|
34 |
|
->booleanNode('hydrate')->defaultTrue()->end() |
301
|
34 |
|
->booleanNode('ignore_missing') |
302
|
34 |
|
->defaultFalse() |
303
|
34 |
|
->info('Silently ignore results returned from Elasticsearch without corresponding persistent object.') |
304
|
34 |
|
->end() |
305
|
34 |
|
->scalarNode('query_builder_method')->defaultValue('createQueryBuilder')->end() |
306
|
34 |
|
->scalarNode('service')->end() |
307
|
34 |
|
->end() |
308
|
34 |
|
->end() |
309
|
34 |
|
->arrayNode('model_to_elastica_transformer') |
310
|
34 |
|
->addDefaultsIfNotSet() |
311
|
34 |
|
->children() |
312
|
34 |
|
->scalarNode('service')->end() |
313
|
34 |
|
->end() |
314
|
34 |
|
->end() |
315
|
34 |
|
->arrayNode('persister') |
316
|
34 |
|
->addDefaultsIfNotSet() |
317
|
34 |
|
->children() |
318
|
34 |
|
->enumNode('refresh') |
319
|
34 |
|
->treatTrueLike('true') |
320
|
34 |
|
->treatFalseLike('false') |
321
|
34 |
|
->values(['true', 'wait_for', 'false']) |
322
|
34 |
|
->end() |
323
|
34 |
|
->scalarNode('service')->end() |
324
|
34 |
|
->end() |
325
|
34 |
|
->end() |
326
|
34 |
|
->end(); |
327
|
|
|
|
328
|
34 |
|
return $node; |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* @return ArrayNodeDefinition|\Symfony\Component\Config\Definition\Builder\NodeDefinition |
333
|
|
|
*/ |
334
|
34 |
|
private function getSerializerNode() |
335
|
|
|
{ |
336
|
34 |
|
$node = $this->createTreeBuilderNode('serializer'); |
337
|
|
|
|
338
|
|
|
$node |
339
|
34 |
|
->addDefaultsIfNotSet() |
340
|
34 |
|
->children() |
341
|
34 |
|
->arrayNode('groups') |
342
|
34 |
|
->treatNullLike([]) |
343
|
34 |
|
->prototype('scalar')->end() |
344
|
34 |
|
->end() |
345
|
34 |
|
->scalarNode('version')->end() |
346
|
34 |
|
->booleanNode('serialize_null') |
347
|
34 |
|
->defaultFalse() |
348
|
34 |
|
->end() |
349
|
34 |
|
->end(); |
350
|
|
|
|
351
|
34 |
|
return $node; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* Adds the configuration for the "clients" key. |
356
|
|
|
*/ |
357
|
34 |
|
private function addClientsSection(ArrayNodeDefinition $rootNode) |
358
|
|
|
{ |
359
|
|
|
$rootNode |
360
|
34 |
|
->fixXmlConfig('client') |
361
|
34 |
|
->children() |
362
|
34 |
|
->arrayNode('clients') |
363
|
34 |
|
->useAttributeAsKey('id') |
364
|
34 |
|
->prototype('array') |
365
|
34 |
|
->performNoDeepMerging() |
366
|
|
|
// Elastica names its properties with camel case, support both |
367
|
34 |
|
->beforeNormalization() |
368
|
|
|
->ifTrue(function ($v) { |
369
|
32 |
|
return isset($v['connection_strategy']); |
370
|
34 |
|
}) |
371
|
|
|
->then(function ($v) { |
372
|
5 |
|
$v['connectionStrategy'] = $v['connection_strategy']; |
373
|
5 |
|
unset($v['connection_strategy']); |
374
|
|
|
|
375
|
5 |
|
return $v; |
376
|
34 |
|
}) |
377
|
34 |
|
->end() |
378
|
|
|
// If there is no connections array key defined, assume a single connection. |
379
|
34 |
|
->beforeNormalization() |
380
|
|
|
->ifTrue(function ($v) { |
381
|
32 |
|
return is_array($v) && !array_key_exists('connections', $v); |
382
|
34 |
|
}) |
383
|
|
|
->then(function ($v) { |
384
|
|
|
return [ |
385
|
32 |
|
'connections' => [$v], |
386
|
|
|
]; |
387
|
34 |
|
}) |
388
|
34 |
|
->end() |
389
|
34 |
|
->children() |
390
|
34 |
|
->arrayNode('connections') |
391
|
34 |
|
->requiresAtLeastOneElement() |
392
|
34 |
|
->prototype('array') |
393
|
34 |
|
->fixXmlConfig('header') |
394
|
34 |
|
->children() |
395
|
34 |
|
->scalarNode('url') |
396
|
34 |
|
->validate() |
397
|
|
|
->ifTrue(function ($url) { |
398
|
18 |
|
return $url && '/' !== substr($url, -1); |
399
|
34 |
|
}) |
400
|
|
|
->then(function ($url) { |
401
|
18 |
|
return $url.'/'; |
402
|
34 |
|
}) |
403
|
34 |
|
->end() |
404
|
34 |
|
->end() |
405
|
34 |
|
->scalarNode('username')->end() |
406
|
34 |
|
->scalarNode('password')->end() |
407
|
34 |
|
->scalarNode('host')->end() |
408
|
34 |
|
->scalarNode('port')->end() |
409
|
34 |
|
->scalarNode('proxy')->end() |
410
|
34 |
|
->arrayNode('http_error_codes') |
411
|
34 |
|
->beforeNormalization() |
412
|
|
|
->ifTrue(function ($v) { return !is_array($v); }) |
413
|
|
|
->then(function ($v) { return array($v); }) |
414
|
34 |
|
->end() |
415
|
34 |
|
->requiresAtLeastOneElement() |
416
|
34 |
|
->defaultValue([400, 403, 404]) |
417
|
34 |
|
->prototype('scalar')->end() |
418
|
34 |
|
->end() |
419
|
34 |
|
->scalarNode('aws_access_key_id')->end() |
420
|
34 |
|
->scalarNode('aws_secret_access_key')->end() |
421
|
34 |
|
->scalarNode('aws_region')->end() |
422
|
34 |
|
->scalarNode('aws_session_token')->end() |
423
|
34 |
|
->booleanNode('ssl')->defaultValue(false)->end() |
424
|
34 |
|
->scalarNode('logger') |
425
|
34 |
|
->defaultValue($this->debug ? 'fos_elastica.logger' : false) |
426
|
34 |
|
->treatNullLike('fos_elastica.logger') |
427
|
34 |
|
->treatTrueLike('fos_elastica.logger') |
428
|
34 |
|
->end() |
429
|
34 |
|
->booleanNode('compression')->defaultValue(false)->end() |
430
|
34 |
|
->arrayNode('headers') |
431
|
34 |
|
->normalizeKeys(false) |
432
|
34 |
|
->useAttributeAsKey('name') |
433
|
34 |
|
->prototype('scalar')->end() |
434
|
34 |
|
->end() |
435
|
34 |
|
->arrayNode('curl') |
436
|
34 |
|
->useAttributeAsKey(CURLOPT_SSL_VERIFYPEER) |
437
|
34 |
|
->prototype('boolean')->end() |
438
|
34 |
|
->end() |
439
|
34 |
|
->scalarNode('transport')->end() |
440
|
34 |
|
->scalarNode('timeout')->end() |
441
|
34 |
|
->scalarNode('connectTimeout')->end() |
442
|
34 |
|
->scalarNode('retryOnConflict') |
443
|
34 |
|
->defaultValue(0) |
444
|
34 |
|
->end() |
445
|
34 |
|
->booleanNode('persistent')->defaultValue(true)->end() |
446
|
34 |
|
->end() |
447
|
34 |
|
->end() |
448
|
34 |
|
->end() |
449
|
34 |
|
->scalarNode('timeout')->end() |
450
|
34 |
|
->scalarNode('connectTimeout')->end() |
451
|
34 |
|
->scalarNode('headers')->end() |
452
|
34 |
|
->scalarNode('connectionStrategy')->defaultValue('Simple')->end() |
453
|
34 |
|
->end() |
454
|
34 |
|
->end() |
455
|
34 |
|
->end() |
456
|
34 |
|
->end() |
457
|
|
|
; |
458
|
34 |
|
} |
459
|
|
|
|
460
|
|
|
/** |
461
|
|
|
* Adds the configuration for the "indexes" key. |
462
|
|
|
*/ |
463
|
34 |
|
private function addIndexesSection(ArrayNodeDefinition $rootNode) |
464
|
|
|
{ |
465
|
|
|
$rootNode |
466
|
34 |
|
->fixXmlConfig('index') |
467
|
34 |
|
->children() |
468
|
34 |
|
->arrayNode('indexes') |
469
|
34 |
|
->useAttributeAsKey('name') |
470
|
34 |
|
->prototype('array') |
471
|
34 |
|
->treatNullLike([]) |
472
|
34 |
|
->beforeNormalization() |
473
|
34 |
|
->ifNull() |
474
|
34 |
|
->thenEmptyArray() |
475
|
34 |
|
->end() |
476
|
|
|
// Support multiple dynamic_template formats to match the old bundle style |
477
|
|
|
// and the way ElasticSearch expects them |
478
|
34 |
|
->beforeNormalization() |
479
|
|
|
->ifTrue(function ($v) { |
480
|
23 |
|
return isset($v['dynamic_templates']); |
481
|
34 |
|
}) |
482
|
|
|
->then(function ($v) { |
483
|
5 |
|
$dt = []; |
484
|
5 |
|
foreach ($v['dynamic_templates'] as $key => $type) { |
485
|
5 |
|
if (is_int($key)) { |
486
|
5 |
|
$dt[] = $type; |
487
|
|
|
} else { |
488
|
|
|
$dt[][$key] = $type; |
489
|
|
|
} |
490
|
|
|
} |
491
|
|
|
|
492
|
5 |
|
$v['dynamic_templates'] = $dt; |
493
|
|
|
|
494
|
5 |
|
return $v; |
495
|
34 |
|
}) |
496
|
34 |
|
->end() |
497
|
34 |
|
->children() |
498
|
34 |
|
->scalarNode('index_name') |
499
|
34 |
|
->info('Defaults to the name of the index, but can be modified if the index name is different in ElasticSearch') |
500
|
34 |
|
->end() |
501
|
34 |
|
->variableNode('indexable_callback')->end() |
502
|
34 |
|
->booleanNode('use_alias')->defaultValue(false)->end() |
503
|
34 |
|
->scalarNode('client')->end() |
504
|
34 |
|
->scalarNode('finder') |
505
|
34 |
|
->treatNullLike(true) |
506
|
34 |
|
->defaultFalse() |
507
|
34 |
|
->end() |
508
|
34 |
|
->append($this->getPersistenceNode()) |
509
|
34 |
|
->append($this->getSerializerNode()) |
510
|
34 |
|
->arrayNode('type_prototype') |
511
|
34 |
|
->children() |
512
|
34 |
|
->scalarNode('analyzer')->end() |
513
|
34 |
|
->append($this->getPersistenceNode()) |
514
|
34 |
|
->append($this->getSerializerNode()) |
515
|
34 |
|
->end() |
516
|
34 |
|
->end() |
517
|
34 |
|
->variableNode('settings')->defaultValue([])->end() |
518
|
34 |
|
->booleanNode('date_detection')->end() |
519
|
34 |
|
->arrayNode('dynamic_date_formats')->prototype('scalar')->end()->end() |
520
|
34 |
|
->scalarNode('analyzer')->end() |
521
|
34 |
|
->booleanNode('numeric_detection')->end() |
522
|
34 |
|
->scalarNode('dynamic')->end() |
523
|
34 |
|
->end() |
524
|
34 |
|
->append($this->getIdNode()) |
525
|
34 |
|
->append($this->getPropertiesNode()) |
526
|
34 |
|
->append($this->getDynamicTemplateNode()) |
527
|
34 |
|
->append($this->getSourceNode()) |
528
|
34 |
|
->append($this->getRoutingNode()) |
529
|
34 |
|
->end() |
530
|
34 |
|
->end() |
531
|
34 |
|
->end() |
532
|
|
|
; |
533
|
34 |
|
} |
534
|
|
|
|
535
|
|
|
/** |
536
|
|
|
* @return ArrayNodeDefinition|\Symfony\Component\Config\Definition\Builder\NodeDefinition |
537
|
|
|
*/ |
538
|
34 |
|
private function createTreeBuilderNode($name) |
539
|
|
|
{ |
540
|
34 |
|
return (new TreeBuilder($name))->getRootNode(); |
541
|
|
|
} |
542
|
|
|
|
543
|
|
|
/** |
544
|
|
|
* Adds the configuration for the "index_templates" key. |
545
|
|
|
* |
546
|
|
|
* @param ArrayNodeDefinition $rootNode |
547
|
|
|
* |
548
|
|
|
* @return void |
549
|
|
|
*/ |
550
|
34 |
|
private function addIndexTemplatesSection(ArrayNodeDefinition $rootNode) |
551
|
|
|
{ |
552
|
|
|
$rootNode |
553
|
34 |
|
->fixXmlConfig('index_template') |
554
|
34 |
|
->children() |
555
|
34 |
|
->arrayNode('index_templates') |
556
|
34 |
|
->useAttributeAsKey('name') |
557
|
34 |
|
->prototype('array') |
558
|
34 |
|
->treatNullLike([]) |
559
|
34 |
|
->beforeNormalization() |
560
|
34 |
|
->ifNull() |
561
|
34 |
|
->thenEmptyArray() |
562
|
34 |
|
->end() |
563
|
|
|
// Support multiple dynamic_template formats to match the old bundle style |
564
|
|
|
// and the way ElasticSearch expects them |
565
|
34 |
|
->beforeNormalization() |
566
|
|
|
->ifTrue(function ($v) { |
567
|
7 |
|
return isset($v['dynamic_templates']); |
568
|
34 |
|
}) |
569
|
|
|
->then(function ($v) { |
570
|
|
|
$dt = []; |
571
|
|
|
foreach ($v['dynamic_templates'] as $key => $type) { |
572
|
|
|
if (is_int($key)) { |
573
|
|
|
$dt[] = $type; |
574
|
|
|
} else { |
575
|
|
|
$dt[][$key] = $type; |
576
|
|
|
} |
577
|
|
|
} |
578
|
|
|
|
579
|
|
|
$v['dynamic_templates'] = $dt; |
580
|
|
|
|
581
|
|
|
return $v; |
582
|
34 |
|
}) |
583
|
34 |
|
->end() |
584
|
34 |
|
->children() |
585
|
34 |
|
->scalarNode('template_name') |
586
|
34 |
|
->info('Defaults to the name of the index template, but can be modified if the index name is different in ElasticSearch') |
587
|
34 |
|
->end() |
588
|
34 |
|
->scalarNode('template')->isRequired()->end() |
589
|
34 |
|
->scalarNode('client')->end() |
590
|
34 |
|
->variableNode('settings')->defaultValue([])->end() |
591
|
34 |
|
->booleanNode('date_detection')->end() |
592
|
34 |
|
->arrayNode('dynamic_date_formats')->prototype('scalar')->end()->end() |
593
|
34 |
|
->scalarNode('analyzer')->end() |
594
|
34 |
|
->booleanNode('numeric_detection')->end() |
595
|
34 |
|
->scalarNode('dynamic')->end() |
596
|
34 |
|
->end() |
597
|
34 |
|
->append($this->getIdNode()) |
598
|
34 |
|
->append($this->getPropertiesNode()) |
599
|
34 |
|
->append($this->getDynamicTemplateNode()) |
600
|
34 |
|
->append($this->getSourceNode()) |
601
|
34 |
|
->append($this->getRoutingNode()) |
602
|
34 |
|
->end() |
603
|
34 |
|
->end() |
604
|
34 |
|
->end() |
605
|
|
|
; |
606
|
34 |
|
} |
607
|
|
|
} |
608
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.