Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony2 Config TreeBuilder validation of array values in YML
    primarykey
    data
    text
    <p>I've got a configuration in YML, that looks like this :</p> <pre><code>foobar_template: templates: homepage: name: "Homepage template" regions: ["top", "main", "left", "bottom"] layout: - [ { region: "top", colspan: 4 } ] - [ { region: "left" }, { region: "main", colspan: 3 } ] - [ { region: "bottom", colspan: 4 } ] subpage: name: "Subpage template" regions: ["top", "main"] layout: - [ { region: "top", colspan: 4 } ] - [ { region: "main", colspan: 4 } ] </code></pre> <p>I've been trying to make sure that this configuration is defined according to specifications, but seem to be unable to make sure that the layout section contains entries that at least define one region. Currently my Configuration.php contains the following :</p> <pre><code>class Configuration implements ConfigurationInterface { /** * {@inheritDoc} */ public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder-&gt;root('foobar_template'); $rootNode -&gt;children() -&gt;arrayNode('templates') -&gt;useAttributeAsKey('template') -&gt;prototype('array') -&gt;children() -&gt;scalarNode('name')-&gt;end() -&gt;arrayNode('regions') -&gt;isRequired() -&gt;requiresAtLeastOneElement() -&gt;prototype('scalar')-&gt;end() -&gt;end() -&gt;append($this-&gt;addLayoutNode()) -&gt;end() -&gt;end() -&gt;end() -&gt;end(); return $treeBuilder; } public function addLayoutNode() { $builder = new TreeBuilder(); $node = $builder-&gt;root('layout'); $node -&gt;isRequired() -&gt;requiresAtLeastOneElement() -&gt;prototype('array') -&gt;prototype('variable')-&gt;end() -&gt;end(); return $node; } } </code></pre> <p>But I would really like to test that the layout blocks specified contain a region (ie. a snippet containing at least <code>- [{ region: &lt;region_name&gt; }]</code>, so what should I use instead of <code>-&gt;prototype('variable')-&gt;end()</code> in addLayoutNode() to actually perform this test? I've tried multiple things, but always run into an InvalidDefinitionException or InvalidConfigurationException when trying to do this. Anyone got an idea on how to test the above in Configuration? (I currently do some sanity checks in the load of the bundle Extension, but it would be cleaner if the Configuration could check this).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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