diff --git a/src/Symfony/Component/Config/Definition/ArrayNode.php b/src/Symfony/Component/Config/Definition/ArrayNode.php index 4a3461119bcfc..96f38dcc9250d 100644 --- a/src/Symfony/Component/Config/Definition/ArrayNode.php +++ b/src/Symfony/Component/Config/Definition/ArrayNode.php @@ -68,7 +68,7 @@ protected function preNormalize($value) /** * Retrieves the children of this node. * - * @return array The children + * @return array */ public function getChildren() { diff --git a/src/Symfony/Component/Config/Definition/Builder/NodeDefinition.php b/src/Symfony/Component/Config/Definition/Builder/NodeDefinition.php index 4d3b2f0bb119c..6cc9bc85cc842 100644 --- a/src/Symfony/Component/Config/Definition/Builder/NodeDefinition.php +++ b/src/Symfony/Component/Config/Definition/Builder/NodeDefinition.php @@ -127,7 +127,9 @@ public function getNode($forceRootNode = false) } $node = $this->createNode(); - $node->setAttributes($this->attributes); + if ($node instanceof BaseNode) { + $node->setAttributes($this->attributes); + } return $node; } diff --git a/src/Symfony/Component/Config/Definition/Dumper/XmlReferenceDumper.php b/src/Symfony/Component/Config/Definition/Dumper/XmlReferenceDumper.php index 8bd47407fa391..29e4076f97ae8 100644 --- a/src/Symfony/Component/Config/Definition/Dumper/XmlReferenceDumper.php +++ b/src/Symfony/Component/Config/Definition/Dumper/XmlReferenceDumper.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Config\Definition\Dumper; use Symfony\Component\Config\Definition\ArrayNode; +use Symfony\Component\Config\Definition\BaseNode; use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\Config\Definition\EnumNode; use Symfony\Component\Config\Definition\NodeInterface; @@ -126,50 +127,52 @@ private function writeNode(NodeInterface $node, int $depth = 0, bool $root = fal // get attributes and elements foreach ($children as $child) { - if (!$child instanceof ArrayNode) { - // get attributes + if ($child instanceof ArrayNode) { + // get elements + $rootChildren[] = $child; - // metadata - $name = str_replace('_', '-', $child->getName()); - $value = '%%%%not_defined%%%%'; // use a string which isn't used in the normal world + continue; + } - // comments - $comments = []; - if ($info = $child->getInfo()) { - $comments[] = $info; - } + // get attributes - if ($example = $child->getExample()) { - $comments[] = 'Example: '.$example; - } + // metadata + $name = str_replace('_', '-', $child->getName()); + $value = '%%%%not_defined%%%%'; // use a string which isn't used in the normal world - if ($child->isRequired()) { - $comments[] = 'Required'; - } + // comments + $comments = []; + if ($child instanceof BaseNode && $info = $child->getInfo()) { + $comments[] = $info; + } - if ($child->isDeprecated()) { - $comments[] = sprintf('Deprecated (%s)', $child->getDeprecationMessage($child->getName(), $node->getPath())); - } + if ($child instanceof BaseNode && $example = $child->getExample()) { + $comments[] = 'Example: '.$example; + } - if ($child instanceof EnumNode) { - $comments[] = 'One of '.implode('; ', array_map('json_encode', $child->getValues())); - } + if ($child->isRequired()) { + $comments[] = 'Required'; + } - if (\count($comments)) { - $rootAttributeComments[$name] = implode(";\n", $comments); - } + if ($child instanceof BaseNode && $child->isDeprecated()) { + $comments[] = sprintf('Deprecated (%s)', $child->getDeprecationMessage($child->getName(), $node->getPath())); + } - // default values - if ($child->hasDefaultValue()) { - $value = $child->getDefaultValue(); - } + if ($child instanceof EnumNode) { + $comments[] = 'One of '.implode('; ', array_map('json_encode', $child->getValues())); + } - // append attribute - $rootAttributes[$name] = $value; - } else { - // get elements - $rootChildren[] = $child; + if (\count($comments)) { + $rootAttributeComments[$name] = implode(";\n", $comments); } + + // default values + if ($child->hasDefaultValue()) { + $value = $child->getDefaultValue(); + } + + // append attribute + $rootAttributes[$name] = $value; } } diff --git a/src/Symfony/Component/Config/Definition/Dumper/YamlReferenceDumper.php b/src/Symfony/Component/Config/Definition/Dumper/YamlReferenceDumper.php index 89103efeaf665..c455344d4b5c5 100644 --- a/src/Symfony/Component/Config/Definition/Dumper/YamlReferenceDumper.php +++ b/src/Symfony/Component/Config/Definition/Dumper/YamlReferenceDumper.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Config\Definition\Dumper; use Symfony\Component\Config\Definition\ArrayNode; +use Symfony\Component\Config\Definition\BaseNode; use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\Config\Definition\EnumNode; use Symfony\Component\Config\Definition\NodeInterface; @@ -76,7 +77,10 @@ private function writeNode(NodeInterface $node, NodeInterface $parentNode = null $default = ''; $defaultArray = null; $children = null; - $example = $node->getExample(); + $example = null; + if ($node instanceof BaseNode) { + $example = $node->getExample(); + } // defaults if ($node instanceof ArrayNode) { @@ -123,7 +127,7 @@ private function writeNode(NodeInterface $node, NodeInterface $parentNode = null } // deprecated? - if ($node->isDeprecated()) { + if ($node instanceof BaseNode && $node->isDeprecated()) { $comments[] = sprintf('Deprecated (%s)', $node->getDeprecationMessage($node->getName(), $parentNode ? $parentNode->getPath() : $node->getPath())); } @@ -138,7 +142,7 @@ private function writeNode(NodeInterface $node, NodeInterface $parentNode = null $key = $prototypedArray ? '-' : $node->getName().':'; $text = rtrim(sprintf('%-21s%s %s', $key, $default, $comments), ' '); - if ($info = $node->getInfo()) { + if ($node instanceof BaseNode && $info = $node->getInfo()) { $this->writeLine(''); // indenting multi-line info $info = str_replace("\n", sprintf("\n%".($depth * 4).'s# ', ' '), $info); diff --git a/src/Symfony/Component/Config/Tests/Definition/Dumper/XmlReferenceDumperTest.php b/src/Symfony/Component/Config/Tests/Definition/Dumper/XmlReferenceDumperTest.php index 1bd60215d7cce..9c2630f1eba92 100644 --- a/src/Symfony/Component/Config/Tests/Definition/Dumper/XmlReferenceDumperTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/Dumper/XmlReferenceDumperTest.php @@ -57,6 +57,7 @@ private function getConfigurationAsString() node-with-a-looong-name="" enum-with-default="this" enum="" + custom-node="true" > diff --git a/src/Symfony/Component/Config/Tests/Definition/Dumper/YamlReferenceDumperTest.php b/src/Symfony/Component/Config/Tests/Definition/Dumper/YamlReferenceDumperTest.php index 1166aafb69933..146917aaa7084 100644 --- a/src/Symfony/Component/Config/Tests/Definition/Dumper/YamlReferenceDumperTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/Dumper/YamlReferenceDumperTest.php @@ -137,6 +137,7 @@ enum: ~ # One of "this"; "that" # Prototype name: [] + custom_node: true EOL; } diff --git a/src/Symfony/Component/Config/Tests/Fixtures/Configuration/CustomNode.php b/src/Symfony/Component/Config/Tests/Fixtures/Configuration/CustomNode.php new file mode 100644 index 0000000000000..1270eb6a68323 --- /dev/null +++ b/src/Symfony/Component/Config/Tests/Fixtures/Configuration/CustomNode.php @@ -0,0 +1,49 @@ +end() ->end() ->end() + ->append(new CustomNodeDefinition('acme')) ->end() ;