L4DD13
L4DD13

Reputation: 220

ZF2 Config: Overriding array values

Within my module configs in ZF2, I have a few values which are arrays consisting of flags for image manipulation.

I need to be able to override these on a project by project basis, however, when I try to it simply merges the 2 arrays. Obviously, I can use keys to override that way, however I need to be able to replace the values as a whole as not all the flags would be required on all projects.

Is there a way to completely override a value when it's an array rather than merging the arrays?

Cheers

Upvotes: 0

Views: 358

Answers (1)

AlexP
AlexP

Reputation: 9857

I need to be able to replace the values as a whole as not all the flags would be required on all projects

If you have multiple installations of ZF2 that share the same module, where they different just in configuration, it would make sense to only define the configuration values that do not differ between projects.

You would then be set the project specific values within a global config file (e.g. config/autoload/module.foo-module.global.config)

All third-party modules use this method; for example Doctrine ODM's module.config.php looks like this:

return array(
    'doctrine' => array(

        'connection' => array(
            'odm_default' => array(
                'server'           => 'localhost',
                'port'             => '27017',
                'connectionString' => null,
                'user'             => null,
                'password'         => null,
                'dbname'           => null,
                'options'          => array()
            ),
         ),
    ),
);

In each project I would then overwrite (which in your case would be to add) the specific config in module.doctrine-mongo-odm.global.php)

return array(
    'doctrine' => array(

        'connection' => array(
            'odm_default' => array(
                'server'    => '10.0.7.9',
                'dbname'    => 'my_database_name',
                'options'   => array(
                    'foo' => 'bar',
                ),
             ),
        ),
    ),
);

The main difference is that you are not removing config values, but rather adding. This makes each of your modules much more reusable.

Upvotes: 1

Related Questions