-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Symfony Config: two new methods for configuration definition tree manipulation to better reuse #27534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@cejen do you want to work on this ? |
fabpot
added a commit
that referenced
this issue
Jun 14, 2019
…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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
I can't find any way to make some parts of configuration definition reuseable. The best approach by me is to add two methods which can provides configuration tree manipulation (similar to DOM manipulation). But any other approach is welcome.
\\Symfony\\Component\\Config\\Definition\\TreeBuilder::findNode(string $path):NodeDefinition
- this method find node on given path (e.g. $node = $treeBuilder->findNode('node_name\node_name\node_name')\\Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::addNode(NodeDefinition $node): NodeDefinition
- this method adds given node under.Example
The text was updated successfully, but these errors were encountered: