Skip to content

Commit 0deaa1e

Browse files
feature #59630 [FrameworkBundle] Add support for info on ArrayNodeDefinition::canBeEnabled() and ArrayNodeDefinition::canBeDisabled() (alexandre-daubois)
This PR was merged into the 7.3 branch. Discussion ---------- [FrameworkBundle] Add support for info on `ArrayNodeDefinition::canBeEnabled()` and `ArrayNodeDefinition::canBeDisabled()` | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | - | License | MIT After #59628 (comment) (cc `@GromNaN`), supersedes #59628 is merged. Commits ------- 857b778 [FrameworkBundle] Add support for info on `ArrayNodeDefinition::canBeEnabled()` and `ArrayNodeDefinition::canBeDisabled()`
2 parents 6ec93be + 857b778 commit 0deaa1e

File tree

4 files changed

+40
-9
lines changed

4 files changed

+40
-9
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,12 +1054,8 @@ private function addValidationSection(ArrayNodeDefinition $rootNode, callable $e
10541054
->end()
10551055
->end()
10561056
->arrayNode('not_compromised_password')
1057-
->canBeDisabled()
1057+
->canBeDisabled('When disabled, compromised passwords will be accepted as valid.')
10581058
->children()
1059-
->booleanNode('enabled')
1060-
->defaultTrue()
1061-
->info('When disabled, compromised passwords will be accepted as valid.')
1062-
->end()
10631059
->scalarNode('endpoint')
10641060
->defaultNull()
10651061
->info('API endpoint for the NotCompromisedPassword Validator.')

src/Symfony/Component/Config/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add `ExprBuilder::ifFalse()`
8+
* Add support for info on `ArrayNodeDefinition::canBeEnabled()` and `ArrayNodeDefinition::canBeDisabled()`
89

910
7.2
1011
---

src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,13 @@ public function canBeUnset(bool $allow = true): static
239239
* enableableArrayNode: {enabled: false, ...} # The config is disabled
240240
* enableableArrayNode: false # The config is disabled
241241
*
242+
* @param string|null $info A description of what happens when the node is enabled or disabled
243+
*
242244
* @return $this
243245
*/
244-
public function canBeEnabled(): static
246+
public function canBeEnabled(/* ?string $info = null */): static
245247
{
246-
$this
248+
$node = $this
247249
->addDefaultsIfNotSet()
248250
->treatFalseLike(['enabled' => false])
249251
->treatTrueLike(['enabled' => true])
@@ -261,6 +263,11 @@ public function canBeEnabled(): static
261263
->defaultFalse()
262264
;
263265

266+
$info = 1 <= \func_num_args() ? func_get_arg(0) : null;
267+
if ($info) {
268+
$node->info($info);
269+
}
270+
264271
return $this;
265272
}
266273

@@ -269,11 +276,13 @@ public function canBeEnabled(): static
269276
*
270277
* By default, the section is enabled.
271278
*
279+
* @param string|null $info A description of what happens when the node is enabled or disabled
280+
*
272281
* @return $this
273282
*/
274-
public function canBeDisabled(): static
283+
public function canBeDisabled(/* ?string $info = null */): static
275284
{
276-
$this
285+
$node = $this
277286
->addDefaultsIfNotSet()
278287
->treatFalseLike(['enabled' => false])
279288
->treatTrueLike(['enabled' => true])
@@ -283,6 +292,11 @@ public function canBeDisabled(): static
283292
->defaultTrue()
284293
;
285294

295+
$info = 1 <= \func_num_args() ? func_get_arg(0) : null;
296+
if ($info) {
297+
$node->info($info);
298+
}
299+
286300
return $this;
287301
}
288302

src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ public function testTrueEnableEnabledNode(array $expected, array $config, string
190190
);
191191
}
192192

193+
public function testCanBeEnabledWithInfo()
194+
{
195+
$node = new ArrayNodeDefinition('root');
196+
$node->canBeEnabled('Some info about disabling this node');
197+
198+
$child = $this->getField($node, 'children')['enabled'];
199+
200+
$this->assertEquals('Some info about disabling this node', $this->getField($child, 'attributes')['info']);
201+
}
202+
193203
public function testCanBeDisabled()
194204
{
195205
$node = new ArrayNodeDefinition('root');
@@ -208,6 +218,16 @@ public function testCanBeDisabled()
208218
$this->assertTrue($this->getField($enabledNode, 'defaultValue'));
209219
}
210220

221+
public function testCanBeDisabledWithInfo()
222+
{
223+
$node = new ArrayNodeDefinition('root');
224+
$node->canBeDisabled('Some info about disabling this node');
225+
226+
$child = $this->getField($node, 'children')['enabled'];
227+
228+
$this->assertEquals('Some info about disabling this node', $this->getField($child, 'attributes')['info']);
229+
}
230+
211231
public function testIgnoreExtraKeys()
212232
{
213233
$node = new ArrayNodeDefinition('root');

0 commit comments

Comments
 (0)