bug #39336 [Config] YamlReferenceDumper: No default value required for VariableNode with array example (Nyholm)

This PR was merged into the 4.4 branch.

Discussion
----------

[Config] YamlReferenceDumper: No default value required for VariableNode with array example

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? |
| Tickets       |
| License       | MIT
| Doc PR        |

This will fix #39328 in a better way.

A `VariableNode` may have an array as value and also a default value as "null". (Like the workflow component).
When we dump the config, we generate invalid yaml:

```
    workflows:
        enabled:              false
        workflows:
            # Prototype
            name:
                # Select which Transition events should be dispatched for this Workflow
                events_to_dispatch:   null

                    # Examples:
                    - workflow.enter
                    - workflow.transition

```

With this PR, we will remove the `null` default value from the dumped config.

#SymfonyHackday

Commits
-------

9104fd4539 [Config] YamlReferenceDumper: No default value required for VariableNode with array example
This commit is contained in:
Fabien Potencier 2020-12-05 18:07:51 +01:00
commit 1f6f693aa5
1 changed files with 4 additions and 0 deletions

View File

@ -17,6 +17,7 @@ use Symfony\Component\Config\Definition\EnumNode;
use Symfony\Component\Config\Definition\NodeInterface;
use Symfony\Component\Config\Definition\PrototypedArrayNode;
use Symfony\Component\Config\Definition\ScalarNode;
use Symfony\Component\Config\Definition\VariableNode;
use Symfony\Component\Yaml\Inline;
/**
@ -95,6 +96,9 @@ class YamlReferenceDumper
} elseif ($node instanceof EnumNode) {
$comments[] = 'One of '.implode('; ', array_map('json_encode', $node->getValues()));
$default = $node->hasDefaultValue() ? Inline::dump($node->getDefaultValue()) : '~';
} elseif (VariableNode::class === get_class($node) && \is_array($example)) {
// If there is an array example, we are sure we dont need to print a default value
$default = '';
} else {
$default = '~';