【发布时间】:2015-10-01 19:43:30
【问题描述】:
在我的 Configuration.php 中,我的结构如下:
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('my_bundle');
$rootNode
->children()
->scalarNode('class')->cannotBeEmpty()->end()
->arrayNode('social_network')
->children()
->arrayNode('facebook')
->validate()
->ifTrue(function($node) {
// my logic to validate if the 'class' specified implements my trait
})
->thenInvalid('You must use XXXXXX trait in your class.')
->end()
->children()
->scalarNode('app_id')->isRequired()->cannotBeEmpty()->end()
->scalarNode('secret')->isRequired()->cannotBeEmpty()->end()
->end()
->end()
->end()
->end()
->end();
return $treeBuilder;
}
我需要检查指定的类是否实现了我的包的特定特征部分。
如何读取function($node) 中class 的值?
【问题讨论】:
标签: validation symfony configuration traits