Skip to content

Commit c28e670

Browse files
authored
Merge pull request #1771 from deguif/remove-dynamic-templates-bc-layer
Remove BC layer for dynamic templates
2 parents e96052f + 726a638 commit c28e670

File tree

2 files changed

+19
-39
lines changed

2 files changed

+19
-39
lines changed

src/DependencyInjection/Configuration.php

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ public function getConfigTreeBuilder()
7676
/**
7777
* Returns the array node used for "dynamic_templates".
7878
*/
79-
private function getDynamicTemplateNode()
79+
private function getDynamicTemplateNode(): ArrayNodeDefinition
8080
{
8181
$node = $this->createTreeBuilderNode('dynamic_templates');
8282

8383
$node
84-
->prototype('array')
85-
->prototype('array')
84+
->arrayPrototype()
85+
->arrayPrototype()
8686
->children()
8787
->scalarNode('match')->end()
8888
->scalarNode('unmatch')->end()
@@ -91,12 +91,18 @@ private function getDynamicTemplateNode()
9191
->scalarNode('path_unmatch')->end()
9292
->scalarNode('match_pattern')->end()
9393
->arrayNode('mapping')
94-
->prototype('variable')
94+
->variablePrototype()
9595
->treatNullLike([])
9696
->end()
9797
->end()
9898
->end()
9999
->end()
100+
->validate()
101+
->ifTrue(static function ($v) {
102+
return 1 !== \count($v);
103+
})
104+
->thenInvalid('Dynamic template should consist of a single named object: %s.')
105+
->end()
100106
->end()
101107
;
102108

@@ -420,33 +426,8 @@ private function addIndexesSection(ArrayNodeDefinition $rootNode)
420426
->children()
421427
->arrayNode('indexes')
422428
->useAttributeAsKey('name')
423-
->prototype('array')
429+
->arrayPrototype()
424430
->treatNullLike([])
425-
->beforeNormalization()
426-
->ifNull()
427-
->thenEmptyArray()
428-
->end()
429-
// Support multiple dynamic_template formats to match the old bundle style
430-
// and the way ElasticSearch expects them
431-
->beforeNormalization()
432-
->ifTrue(function ($v) {
433-
return isset($v['dynamic_templates']);
434-
})
435-
->then(function ($v) {
436-
$dt = [];
437-
foreach ($v['dynamic_templates'] as $key => $type) {
438-
if (\is_int($key)) {
439-
$dt[] = $type;
440-
} else {
441-
$dt[][$key] = $type;
442-
}
443-
}
444-
445-
$v['dynamic_templates'] = $dt;
446-
447-
return $v;
448-
})
449-
->end()
450431
->children()
451432
->scalarNode('index_name')
452433
->info('Defaults to the name of the index, but can be modified if the index name is different in ElasticSearch')

tests/Unit/DependencyInjection/ConfigurationTest.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,16 @@ public function testClientConfigurationNoUrl()
171171
$this->assertTrue(empty($configuration['clients']['default']['connections'][0]['url']));
172172
}
173173

174-
public function testUnconfiguredType()
174+
public function testUnconfiguredIndex()
175175
{
176176
$configuration = $this->getConfigs([
177-
'clients' => [
178-
'default' => ['url' => 'http://localhost:9200'],
179-
],
180-
'indexes' => [
181-
'test' => [
182-
],
183-
],
184-
]);
177+
'clients' => [
178+
'default' => ['url' => 'http://localhost:9200'],
179+
],
180+
'indexes' => [
181+
'test' => null,
182+
],
183+
]);
185184

186185
$this->assertArrayHasKey('properties', $configuration['indexes']['test']);
187186
}

0 commit comments

Comments
 (0)