A.5. Universal Configuration

A.5.1. Config File Settings

Now, if your config file has an 'Solar_Example' group in it, those values will override any of the default values set by your class definition. Say your config file looks something like this:

<?php
$config = array();
// ...
$config['Solar_Example']['opt_3'] = 'dib';
// ...
return $config;

When you instantiate the Solar_Example object, the config file values will override the default values, leaving all others in place:

<?php
$example = Solar::factory('Solar_Example');
/**
 * 
 * The values of $example->_config are now:
 * 
 * 'opt_1' => 'foo'
 * 'opt_2' => 'bar'
 * 'opt_3' => 'dib' // from the config file
 */

A.5.2. Instantiation Settings

Finally, if you specify a configuration array as the second parameter of Solar::factory(), those values override both the default values of the class definition and the Solar.config.php values.

<?php
$config = array('opt_2' => 'gir');
$example = Solar::factory('Solar_Example', $config);
/**
 * The values of $example->_config are now:
 * 
 * 'opt_1' => 'foo' // as defined by the class
 * 'opt_2' => 'gir' // from the Solar::factory() instantiation config
 * 'opt_3' => 'dib' // from the config file
 */

A.5.3. Order of Precedence

All of this is to say that the order of precedence for config values looks like this:

  • The values start as defined by the class,

  • And are overwritten by any config file values,

  • And are again overwritten by values set at instantiation time

Note that values not changed remain the same, so if you leave one out, it's not overwritten to be null.



Local