Note that there are some explanatory texts on larger screens.

plurals
  1. POTreebuilder Validation for yml file
    text
    copied!<p>I created a Configuration class and build a tree that defines my configuration in that class,but i guess it's very ugly then my question is to find a solution to simplify my calss?</p> <pre><code>&lt;?php namespace Myapp\Mybundle\DependencyInjection; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; class Configuration implements ConfigurationInterface { /** * {@inheritDoc} */ public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder-&gt;root('em_profession'); $rootNode -&gt;children() -&gt;arrayNode('region') -&gt;isRequired() -&gt;requiresAtLeastOneElement() -&gt;useAttributeAsKey('id') -&gt;prototype('array') -&gt;children() -&gt;scalarNode('label') -&gt;isRequired() -&gt;cannotBeEmpty()-&gt;defaultValue('em_profession_label')-&gt;end() -&gt;arrayNode('childrens') -&gt;isRequired() -&gt;requiresAtLeastOneElement() -&gt;useAttributeAsKey('id') -&gt;prototype('array') -&gt;children() -&gt;scalarNode('label')-&gt;end() -&gt;arrayNode('childrens') -&gt;isRequired() -&gt;requiresAtLeastOneElement() -&gt;useAttributeAsKey('id') -&gt;prototype('array') -&gt;children() -&gt;scalarNode('label')-&gt;end() -&gt;arrayNode('childrens') -&gt;isRequired() -&gt;requiresAtLeastOneElement() -&gt;useAttributeAsKey('id') -&gt;prototype('array') -&gt;children() -&gt;scalarNode('label')-&gt;end() -&gt;arrayNode('childrens') -&gt;isRequired() -&gt;requiresAtLeastOneElement() -&gt;useAttributeAsKey('id') -&gt;prototype('array') -&gt;children() -&gt;scalarNode('label')-&gt;end() -&gt;arrayNode('childrens') -&gt;isRequired() -&gt;requiresAtLeastOneElement() -&gt;useAttributeAsKey('id') -&gt;prototype('array') -&gt;end() -&gt;end() -&gt;end() -&gt;end() -&gt;end() -&gt;end() -&gt;end() -&gt;end() -&gt;end() -&gt;end() -&gt;end() -&gt;end() -&gt;end() -&gt;end() -&gt;end() -&gt;end() -&gt;end() -&gt;end() ; return $treeBuilder; } </code></pre> <p>My configuration works fine but it's very big so I wich to minimise it to simplify it and to stop the repetition of code...</p> <p><strong>edit</strong></p> <p>OK I know this solution but I guess I cant applicate it in my configuration,for exemple in Twig configuration file they use a custom function in the end of class after "->end()" but in my configuration i use it inside "prototype()" also I have a lot of repetition of code but child inside child inside child...so it's deficult to minimise it correctly... </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload