Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #31287 [Config] Introduce find method in ArrayNodeDefinition …
…to ease configuration tree manipulation (jschaedl) This PR was squashed before being merged into the 4.4 branch (closes #31287). Discussion ---------- [Config] Introduce find method in ArrayNodeDefinition to ease configuration tree manipulation | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #27534 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | tbd. ### Description This PR introduces a new `find(string $nodePath)`method in the `ArrayNodeDefinition` class, which helps you finding the right node to prepend configuration to ease configuration tree manipulation. ### How to use it ```php class Configuration implements ConfigurationInterface { public function getConfigTreeBuilder() { ... $rootNode ->children() ->arrayNode('social_media_channels') ->children() ->booleanNode('enable')->end() ->arrayNode('twitter')->end() ->arrayNode('facebook')->end() ->arrayNode('instagram')->end() ->end() ->end() ->end() ; $this->changeSocialMediaChannelConfiguration($rootNode->find('social_media_channels.enable')); $this->addTwitterConfiguration($rootNode->find('social_media_channels.twitter')); $this->addFacebookConfiguration($rootNode->find('social_media_channels.facebook')); $this->addInstagramConfiguration($rootNode->find('social_media_channels.instagram')); return $treeBuilder; } private function changeSocialMediaChannelConfiguration(NodeDefinition $node) { $node ->defaultTrue() ; } private function addTwitterConfiguration(NodeDefinition $node) { $node ->children() ->integerNode('client_id')->end() ->scalarNode('client_secret')->end() ->end() ; } private function addFacebookConfiguration(NodeDefinition $node) { $node ->children() ->integerNode('client_id')->end() ->scalarNode('client_secret')->end() ->end() ; } private function addInstagramConfiguration(NodeDefinition $node) { $node ->children() ->integerNode('client_id')->end() ->scalarNode('client_secret')->end() ->end() ; } } ``` Commits ------- e3b248a [Config] Introduce find method in ArrayNodeDefinition to ease configuration tree manipulation
- Loading branch information