From 857b7784b29459f831b7fd0d886fc9ead64b43cc Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Mon, 27 Jan 2025 13:38:29 +0100 Subject: [PATCH] [FrameworkBundle] Add support for info on `ArrayNodeDefinition::canBeEnabled()` and `ArrayNodeDefinition::canBeDisabled()` --- .../DependencyInjection/Configuration.php | 6 +---- src/Symfony/Component/Config/CHANGELOG.md | 1 + .../Builder/ArrayNodeDefinition.php | 22 +++++++++++++++---- .../Builder/ArrayNodeDefinitionTest.php | 20 +++++++++++++++++ 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 265fba9fd1f2d..c765f22ce61d4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -1054,12 +1054,8 @@ private function addValidationSection(ArrayNodeDefinition $rootNode, callable $e ->end() ->end() ->arrayNode('not_compromised_password') - ->canBeDisabled() + ->canBeDisabled('When disabled, compromised passwords will be accepted as valid.') ->children() - ->booleanNode('enabled') - ->defaultTrue() - ->info('When disabled, compromised passwords will be accepted as valid.') - ->end() ->scalarNode('endpoint') ->defaultNull() ->info('API endpoint for the NotCompromisedPassword Validator.') diff --git a/src/Symfony/Component/Config/CHANGELOG.md b/src/Symfony/Component/Config/CHANGELOG.md index 2efbf70080de1..577fbbca53645 100644 --- a/src/Symfony/Component/Config/CHANGELOG.md +++ b/src/Symfony/Component/Config/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG --- * Add `ExprBuilder::ifFalse()` + * Add support for info on `ArrayNodeDefinition::canBeEnabled()` and `ArrayNodeDefinition::canBeDisabled()` 7.2 --- diff --git a/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php b/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php index 6b75ba137a806..0f2245dfcb5b4 100644 --- a/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +++ b/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php @@ -239,11 +239,13 @@ public function canBeUnset(bool $allow = true): static * enableableArrayNode: {enabled: false, ...} # The config is disabled * enableableArrayNode: false # The config is disabled * + * @param string|null $info A description of what happens when the node is enabled or disabled + * * @return $this */ - public function canBeEnabled(): static + public function canBeEnabled(/* ?string $info = null */): static { - $this + $node = $this ->addDefaultsIfNotSet() ->treatFalseLike(['enabled' => false]) ->treatTrueLike(['enabled' => true]) @@ -261,6 +263,11 @@ public function canBeEnabled(): static ->defaultFalse() ; + $info = 1 <= \func_num_args() ? func_get_arg(0) : null; + if ($info) { + $node->info($info); + } + return $this; } @@ -269,11 +276,13 @@ public function canBeEnabled(): static * * By default, the section is enabled. * + * @param string|null $info A description of what happens when the node is enabled or disabled + * * @return $this */ - public function canBeDisabled(): static + public function canBeDisabled(/* ?string $info = null */): static { - $this + $node = $this ->addDefaultsIfNotSet() ->treatFalseLike(['enabled' => false]) ->treatTrueLike(['enabled' => true]) @@ -283,6 +292,11 @@ public function canBeDisabled(): static ->defaultTrue() ; + $info = 1 <= \func_num_args() ? func_get_arg(0) : null; + if ($info) { + $node->info($info); + } + return $this; } diff --git a/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php b/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php index ca376ea8a79df..281813a8cd0f1 100644 --- a/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php @@ -190,6 +190,16 @@ public function testTrueEnableEnabledNode(array $expected, array $config, string ); } + public function testCanBeEnabledWithInfo() + { + $node = new ArrayNodeDefinition('root'); + $node->canBeEnabled('Some info about disabling this node'); + + $child = $this->getField($node, 'children')['enabled']; + + $this->assertEquals('Some info about disabling this node', $this->getField($child, 'attributes')['info']); + } + public function testCanBeDisabled() { $node = new ArrayNodeDefinition('root'); @@ -208,6 +218,16 @@ public function testCanBeDisabled() $this->assertTrue($this->getField($enabledNode, 'defaultValue')); } + public function testCanBeDisabledWithInfo() + { + $node = new ArrayNodeDefinition('root'); + $node->canBeDisabled('Some info about disabling this node'); + + $child = $this->getField($node, 'children')['enabled']; + + $this->assertEquals('Some info about disabling this node', $this->getField($child, 'attributes')['info']); + } + public function testIgnoreExtraKeys() { $node = new ArrayNodeDefinition('root'); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy