Skip to content

Commit 7fc7e18

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: synchronize Redis proxy traits for different versions [Serializer] Fixed BackedEnumNormalizer priority for translatable enum [Config] Fix `YamlReferenceDumper` handling of array examples
2 parents fbcb92b + 18ac9da commit 7fc7e18

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

Definition/Dumper/YamlReferenceDumper.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Symfony\Component\Config\Definition\NodeInterface;
1919
use Symfony\Component\Config\Definition\PrototypedArrayNode;
2020
use Symfony\Component\Config\Definition\ScalarNode;
21-
use Symfony\Component\Config\Definition\VariableNode;
2221
use Symfony\Component\Yaml\Inline;
2322

2423
/**
@@ -90,19 +89,12 @@ private function writeNode(NodeInterface $node, ?NodeInterface $parentNode = nul
9089
$children = $this->getPrototypeChildren($node);
9190
}
9291

93-
if (!$children) {
94-
if ($node->hasDefaultValue() && \count($defaultArray = $node->getDefaultValue())) {
95-
$default = '';
96-
} elseif (!\is_array($example)) {
97-
$default = '[]';
98-
}
92+
if (!$children && !($node->hasDefaultValue() && \count($defaultArray = $node->getDefaultValue()))) {
93+
$default = '[]';
9994
}
10095
} elseif ($node instanceof EnumNode) {
10196
$comments[] = 'One of '.$node->getPermissibleValues('; ');
10297
$default = $node->hasDefaultValue() ? Inline::dump($node->getDefaultValue()) : '~';
103-
} elseif (VariableNode::class === $node::class && \is_array($example)) {
104-
// If there is an array example, we are sure we dont need to print a default value
105-
$default = '';
10698
} else {
10799
$default = '~';
108100

@@ -203,14 +195,16 @@ private function writeArray(array $array, int $depth, bool $asComment = false):
203195
}
204196
$prefix = $asComment ? '# ' : '';
205197

198+
$prefix = $asComment ? '# ' : '';
199+
206200
if ($isIndexed) {
207201
$this->writeLine($prefix.'- '.$val, $depth * 4);
208202
} else {
209-
$this->writeLine($prefix.sprintf('%-20s %s', $key.':', $val), $depth * 4);
203+
$this->writeLine(sprintf('%s%-20s %s', $prefix, $key.':', $val), $depth * 4);
210204
}
211205

212206
if (\is_array($value)) {
213-
$this->writeArray($value, $depth + 1);
207+
$this->writeArray($value, $depth + 1, $asComment);
214208
}
215209
}
216210
}

Tests/Definition/Dumper/XmlReferenceDumperTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ enum=""
109109
110110
</pipou>
111111
112+
<array-with-array-example-and-no-default-value />
113+
112114
</config>
113115

114116
EOL

Tests/Definition/Dumper/YamlReferenceDumperTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ enum: ~ # One of "this"; "that"; Symfony\Component\Config\Tests\
114114
# which should be indented
115115
child3: ~ # Example: 'example setting'
116116
scalar_prototyped: []
117-
variable:
117+
variable: ~
118118
119119
# Examples:
120120
# - foo
@@ -142,6 +142,11 @@ enum: ~ # One of "this"; "that"; Symfony\Component\Config\Tests\
142142
143143
# Prototype
144144
name: []
145+
array_with_array_example_and_no_default_value: []
146+
147+
# Examples:
148+
# - foo
149+
# - bar
145150
custom_node: true
146151

147152
EOL;

Tests/Fixtures/Configuration/ExampleConfiguration.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ public function getConfigTreeBuilder(): TreeBuilder
9797
->end()
9898
->end()
9999
->end()
100+
->arrayNode('array_with_array_example_and_no_default_value')
101+
->example(['foo', 'bar'])
102+
->end()
100103
->append(new CustomNodeDefinition('acme'))
101104
->end()
102105
;

0 commit comments

Comments
 (0)