feature #19480 [Config] Fix (Yaml|Xml)ReferenceDumper for nested prototypes (ogizanagi)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[Config] Fix (Yaml|Xml)ReferenceDumper for nested prototypes

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

This tries to fix the nested prototypes case for the `YamlReferenceDumper` and `XmlReferenceDumper`.

### Before
```yml
cms_pages:

    # Prototype
    page:                 []
```

### After

```yml
cms_pages:

    # Prototype
    page:

        # Prototype
        locale:
            title:                ~ # Required
            path:                 ~ # Required
```

~~However, the `YamlReferenceDumperTest::testDumper` is marked as skipped, due to another unsupported prototype usage, but that's another issue (the `connections` key). Thus, the bug fix must be tested manually :/ (I'd recommend to merge #19570 first)~~

Commits
-------

1e80510 [Config] Fix YamlReferenceDumper for nested prototypes
This commit is contained in:
Fabien Potencier 2016-09-16 08:01:32 -07:00
commit c21bed7fed
5 changed files with 47 additions and 2 deletions

View File

@ -96,7 +96,10 @@ class XmlReferenceDumper
$rootAttributes[$key] = str_replace('-', ' ', $rootName).' '.$key;
}
if ($prototype instanceof ArrayNode) {
if ($prototype instanceof PrototypedArrayNode) {
$prototype->setName($key);
$children = array($key => $prototype);
} elseif ($prototype instanceof ArrayNode) {
$children = $prototype->getChildren();
} else {
if ($prototype->hasDefaultValue()) {

View File

@ -199,8 +199,14 @@ class YamlReferenceDumper
if ($prototype instanceof ArrayNode) {
$keyNode = new ArrayNode($key, $node);
$children = $prototype->getChildren();
if ($prototype instanceof PrototypedArrayNode) {
$children = $this->getPrototypeChildren($prototype);
}
// add children
foreach ($prototype->getChildren() as $childNode) {
foreach ($children as $childNode) {
$keyNode->addChild($childNode);
}
} else {

View File

@ -78,6 +78,20 @@ class XmlReferenceDumperTest extends \PHPUnit_Framework_TestCase
pass=""
/>
<!-- prototype -->
<cms-page page="cms page page">
<!-- prototype -->
<!-- title: Required -->
<!-- path: Required -->
<page
locale="page locale"
title=""
path=""
/>
</cms-page>
</config>
EOL

View File

@ -65,6 +65,15 @@ acme_root:
-
user: ~
pass: ~
cms_pages:
# Prototype
page:
# Prototype
locale:
title: ~ # Required
path: ~ # Required
EOL;
}

View File

@ -24,6 +24,7 @@ class ExampleConfiguration implements ConfigurationInterface
$rootNode
->fixXmlConfig('parameter')
->fixXmlConfig('connection')
->fixXmlConfig('cms_page')
->children()
->booleanNode('boolean')->defaultTrue()->end()
->scalarNode('scalar_empty')->end()
@ -67,6 +68,18 @@ class ExampleConfiguration implements ConfigurationInterface
->end()
->end()
->end()
->arrayNode('cms_pages')
->useAttributeAsKey('page')
->prototype('array')
->useAttributeAsKey('locale')
->prototype('array')
->children()
->scalarNode('title')->isRequired()->end()
->scalarNode('path')->isRequired()->end()
->end()
->end()
->end()
->end()
->end()
;