我在 YML 中有一个配置,如下所示:
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 } ]
我一直在尝试确保根据规范定义此配置,但似乎无法确保布局部分包含至少定义一个区域的条目。目前我的 Configuration.php 包含以下内容:
class Configuration implements ConfigurationInterface
{
/**
* {@inheritDoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('foobar_template');
$rootNode
->children()
->arrayNode('templates')
->useAttributeAsKey('template')
->prototype('array')
->children()
->scalarNode('name')->end()
->arrayNode('regions')
->isRequired()
->requiresAtLeastOneElement()
->prototype('scalar')->end()
->end()
->append($this->addLayoutNode())
->end()
->end()
->end()
->end();
return $treeBuilder;
}
public function addLayoutNode()
{
$builder = new TreeBuilder();
$node = $builder->root('layout');
$node
->isRequired()
->requiresAtLeastOneElement()
->prototype('array')
->prototype('variable')->end()
->end();
return $node;
}
}
但我真的很想测试指定的布局块是否包含一个区域(即一个至少包含 的片段- [{ region: <region_name> }]
,那么我应该使用什么而不是->prototype('variable')->end()
addLayoutNode() 来实际执行此测试?我尝试了多种方法,但总是尝试执行此操作时遇到 InvalidDefinitionException 或 InvalidConfigurationException。有人知道如何在 Configuration 中测试上述内容吗?(我目前在 bundle Extension 的负载中进行了一些健全性检查,但如果 Configuration 可以检查它会更干净这个)。