社区我需要您的帮助。我有配置文件:
payments:
methods:
paypal:
enabled: false
allowed_countries:
- <country>
- ...
credit_card:
disallowed_countries:
- <country>
- ...
如果arrayNode仅包含两个允许的数组之一(allowed_countries或disallowed_countries),并且如果同时存在两个数组,则抛出异常,如何使用TreeBuilder进行验证?Symfony 3.2版
您可以通过在ExprBuilder中使用验证规则,将更复杂的验证添加到配置树构建器中。
这看起来像:
$rootNode
->isRequired()
->validate()
->ifTrue(function($options) {
return !($options['allowed_countries'] xor $options['disallowed_countries']);
})
->thenInvalid('Either define allowed_countries or disallowed_countries, not both')
->end()
->children()
->arrayNode('allowed_countries')
->scalarPrototype()->end()
->end()
->arrayNode('disallowed_countries')
->scalarPrototype()->end()
->end()
->end();
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句