Commit cb9b317
committed
feature #19764 [Config] Add ExprBuilder::ifEmpty() (ogizanagi)
This PR was merged into the 3.2-dev branch.
Discussion
----------
[Config] Add ExprBuilder::ifEmpty()
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT
| Doc PR | symfony/symfony-docs#6922
Useful for instance when you don't expect to have a key set in the resolved config if its content is empty:
```php
$builder = new TreeBuilder();
$tree = $builder
->root('matcher')
->children()
->arrayNode('references_to_exclude')
->validate()
->ifEmpty()
->thenUnset()
->end()
->prototype('scalar')->end()
->end()
->end()
->end()
->buildTree()
;
$tree->finalize(['references_to_exclude' => ['foo', 'bar']]);
>>> ['references_to_exclude' => ['foo', 'bar']]
$tree->finalize(['references_to_exclude' => []]);
>>> []
```
Commits
-------
4e46f64 [Config] Add ExprBuilder::ifEmpty()File tree
2 files changed
+27
-0
lines changed- Definition/Builder
- Tests/Definition/Builder
2 files changed
+27
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
100 | 112 | | |
101 | 113 | | |
102 | 114 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
78 | 93 | | |
79 | 94 | | |
80 | 95 | | |
| |||
0 commit comments