我有一个从packagist.org导入的软件包,位于供应商目录中 此捆绑包具有带参数
的services.yml配置文件parameters:
myservice.class: ...
myservice.options:
MERCHANT_ID: '11223344556677'
ACCESS_KEY: YourAccesKey
...
我想在 app / config / parameters.yml 中覆盖一个参数,但它会删除所有myservice.options数组
parameters:
myservice.options:
MERCHANT_ID: '99999999999999'
如何只覆盖一个参数?
答案 0 :(得分:4)
您应该公开您的捆绑配置,以及在此处执行此操作的文档:
以下代码基础。应该对数组的每个参数进行
// ACME/YourBundle/DependencyInjection/Configuration.php
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('your_bundle');
$rootNode
->children()
->arrayNode('parameters')
->prototype('array')
->treatNullLike(array())
->children()
->scalarNode('MERCHANT_ID')
->isRequired()
->cannotBeEmpty()
->end()
[...] // Another node
->end()
->end()
->end()
->end()
->end()
;
return $treeBuilder;
}
然后他的config.yml
文件中的每个用户都将定义他的私有参数:
your_bundle
parameters:
MERCHANT_ID: XXXXXX