在app/config/config.yml
我为我的包添加了一些自定义设置
acme:
acme_services:
service_a:
options: { name: I, id: X, type: F, error: E }
service_b:
options: { name: J, id: Z, type: F, error: E }
现在src/ACME/Bundle/ACMEBundle/DependencyInjection/Configuration.php
如何设置默认值和/
或检查service_a
/ service_b
?
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('acme');
$rootNode
->children()
// also removed the ->end() for each arrayNode but then I get a Fatal Error
->arrayNode('acme_services')->end()
->arrayNode('another')->end()
->arrayNode('more')->end()
->arrayNode('blah')->end()
->end();
return $treeBuilder;
}
所以我需要拉取service_a
andservice_b
数组,但我得到and的Unrecognized options
错误。service_a
service_b
期望的结果是我想同时拥有service_a
和service_b
在acme_services
数组中,这就是为什么我可以针对使用acme_services
的任何服务验证数组,无论是service_a
还是service_b
。
注意:在 PHP 中我会这样写:(不确定这是否正确,但这是一个示例)
$acme_services = array(
'acme_services' =>
'service_a' => array(
'options' => array(
'name' => 'I',
'id' => 'X',
'type' => 'F',
'error'=> 'E',
)
),
'service_b' => array(
'options' => array(
'name' => 'J',
'id' => 'Z',
'type' => 'F',
'error'=> 'E',
)
)
);