Merge pull request #423 from FriendsOfSymfony/dynamic-templates
Apply same mapping logic to dynamic templates...
This commit is contained in:
commit
6c4740b292
|
@ -339,18 +339,13 @@ class Configuration implements ConfigurationInterface
|
|||
->useAttributeAsKey('name')
|
||||
->prototype('array')
|
||||
->children()
|
||||
->scalarNode('match')->isRequired()->end()
|
||||
->scalarNode('match')->end()
|
||||
->scalarNode('unmatch')->end()
|
||||
->scalarNode('match_mapping_type')->end()
|
||||
->arrayNode('mapping')
|
||||
->isRequired()
|
||||
->children()
|
||||
->scalarNode('type')->end()
|
||||
->scalarNode('index')->end()
|
||||
->arrayNode('fields')
|
||||
->children()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->scalarNode('path_match')->end()
|
||||
->scalarNode('path_unmatch')->end()
|
||||
->scalarNode('match_pattern')->end()
|
||||
->append($this->getDynamicTemplateMapping())
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
|
@ -358,6 +353,21 @@ class Configuration implements ConfigurationInterface
|
|||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the array node used for mapping in dynamic templates
|
||||
*/
|
||||
protected function getDynamicTemplateMapping()
|
||||
{
|
||||
$builder = new TreeBuilder();
|
||||
$node = $builder->root('mapping');
|
||||
|
||||
$nestings = $this->getNestingsForDynamicTemplates();
|
||||
|
||||
$this->addFieldConfig($node->children(), $nestings);
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Symfony\Component\Config\Definition\Builder\NodeBuilder $node The node to which to attach the field config to
|
||||
* @param array $nestings the nested mappings for the current field level
|
||||
|
@ -451,6 +461,41 @@ class Configuration implements ConfigurationInterface
|
|||
return $nestings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array The unique nested mappings for all dynamic templates
|
||||
*/
|
||||
protected function getNestingsForDynamicTemplates()
|
||||
{
|
||||
if (!isset($this->configArray[0]['indexes'])) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$nestings = array();
|
||||
foreach ($this->configArray[0]['indexes'] as $index) {
|
||||
if (empty($index['types'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($index['types'] as $type) {
|
||||
if (empty($type['dynamic_templates'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($type['dynamic_templates'] as $definition) {
|
||||
$field = $definition['mapping'];
|
||||
|
||||
if (isset($field['fields'])) {
|
||||
$this->addPropertyNesting($field, $nestings, 'fields');
|
||||
} else if (isset($field['properties'])) {
|
||||
$this->addPropertyNesting($field, $nestings, 'properties');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return $nestings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $mappings The mappings for the current type
|
||||
* @return array The nested mappings defined for this type
|
||||
|
|
|
@ -48,6 +48,22 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertInstanceOf('Symfony\Component\Config\Definition\ScalarNode', $dynamicTemplates['match_mapping_type']);
|
||||
$this->assertNull($dynamicTemplates['match_mapping_type']->getDefaultValue());
|
||||
|
||||
$this->assertArrayHasKey('unmatch', $dynamicTemplates);
|
||||
$this->assertInstanceOf('Symfony\Component\Config\Definition\ScalarNode', $dynamicTemplates['unmatch']);
|
||||
$this->assertNull($dynamicTemplates['unmatch']->getDefaultValue());
|
||||
|
||||
$this->assertArrayHasKey('path_match', $dynamicTemplates);
|
||||
$this->assertInstanceOf('Symfony\Component\Config\Definition\ScalarNode', $dynamicTemplates['path_match']);
|
||||
$this->assertNull($dynamicTemplates['path_match']->getDefaultValue());
|
||||
|
||||
$this->assertArrayHasKey('path_unmatch', $dynamicTemplates);
|
||||
$this->assertInstanceOf('Symfony\Component\Config\Definition\ScalarNode', $dynamicTemplates['path_unmatch']);
|
||||
$this->assertNull($dynamicTemplates['path_unmatch']->getDefaultValue());
|
||||
|
||||
$this->assertArrayHasKey('match_pattern', $dynamicTemplates);
|
||||
$this->assertInstanceOf('Symfony\Component\Config\Definition\ScalarNode', $dynamicTemplates['match_pattern']);
|
||||
$this->assertNull($dynamicTemplates['match_pattern']->getDefaultValue());
|
||||
|
||||
$this->assertArrayHasKey('mapping', $dynamicTemplates);
|
||||
$this->assertInstanceOf('Symfony\Component\Config\Definition\ArrayNode', $dynamicTemplates['mapping']);
|
||||
}
|
||||
|
@ -63,13 +79,10 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
$this->assertArrayHasKey('type', $mapping);
|
||||
$this->assertInstanceOf('Symfony\Component\Config\Definition\ScalarNode', $mapping['type']);
|
||||
$this->assertNull($mapping['type']->getDefaultValue());
|
||||
$this->assertSame('string', $mapping['type']->getDefaultValue());
|
||||
|
||||
$this->assertArrayHasKey('index', $mapping);
|
||||
$this->assertInstanceOf('Symfony\Component\Config\Definition\ScalarNode', $mapping['index']);
|
||||
$this->assertNull($mapping['index']->getDefaultValue());
|
||||
|
||||
$this->assertArrayHasKey('fields', $mapping);
|
||||
$this->assertInstanceOf('Symfony\Component\Config\Definition\ArrayNode', $mapping['fields']);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue