4
votes

I have a bundle imported from packagist.org and located into vendor directory
This bundle has a services.yml configuration file with parameters

parameters:
    myservice.class: ...
    myservice.options:
        MERCHANT_ID: '11223344556677'
        ACCESS_KEY: YourAccesKey
        ...

I want to override just one parameter in my app/config/parameters.yml but it delete all myservice.options array

parameters:
    myservice.options:
        MERCHANT_ID: '99999999999999'

how to override just one parameter ?

1
Bundles should use the DIC configuration to set default values, maybe you should commit a pull request to the bundle. If you can tell us the name probably we can help.skler
my bundle : packagist.org/packages/stloc/payline-bundle. I hope that future users define their own identifierstloc
there are differents solutions as pull request but the best way is to use parameter filestloc

1 Answers

4
votes

You should expose your bundle configuration, the doc to do that it's here:

http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class

A base of code below. Should be done for every parameters of the array

// 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;
}

And then every user in his config.yml file will define his private parameters:

your_bundle
    parameters:
        MERCHANT_ID: XXXXXX