Pragmatism in the real world

Akrabat_Config (5)

Matthew Delmarter noticed a problem with Akrabat_Config. Essentially when you load a single section that overrides one item of a nested array from another section, all the other items get “lost”.

I’ve fixed it and this time thought I’d supply a zip file of the files!
Akrabat_Config-0.5.zip
Akrabat_Config_Tests-0.5.zip

I’ve also updated the code so that it can support different types of config files. We now have Akrabat_Config_Abstract and Akrabat_Config_Ini.

A test for the bug is as follows:
function testNestedOverrides()
{
$config = new Akrabat_Config_Ini($this->_iniFileConfig, 'test');
zend::dump($config);
$this->assertEquals('staging', $config->db['name']);
$this->assertEquals('username', $config->db['user']);
}

using this config.ini:

[all]
hostname = all
akey = avalue
test.me = all
db.host = 127.0.0.1
db.user = username
db.pass = password

[test]
include = all
db.name = staging

The failure occurs because $config->db[‘user’] is not set. To fix it, I have introduced a local version of array_merge_recursive that overwrites keys that already exist. This is different from php’s array_merge_recursive which creates a subarray in that instance.

i.e.
< ?php $ar1 = array("color" => array("favorite" => "red"), 5);
$ar2 = array(10, "color" => array("favorite" => "green", "blue"));
$result = array_merge_recursive($ar1, $ar2);
?>

produces the $result:

Array
(
[color] => Array
(
[favorite] => Array
(
[0] => red
[1] => green
)

[0] => blue
)

[0] => 5
[1] => 10
)

whereas I need a $result of:

Array
(
[color] => Array
(
[favorite] => green
[0] => blue
)

[0] => 5
[1] => 10
)

Thanks Matthew for noticing!

update: Fixed links to zip files. Thanks Ivan!

One thought on “Akrabat_Config (5)

  1. Hi,

    Just to tell you the links are dead
    (excuse my poor english, I'm french ;) )

Comments are closed.