diff --git a/library/Zend/Config/Reader/Ini.php b/library/Zend/Config/Reader/Ini.php index cd06bc915ca..c264a115d8a 100644 --- a/library/Zend/Config/Reader/Ini.php +++ b/library/Zend/Config/Reader/Ini.php @@ -131,8 +131,8 @@ protected function process(array $data) foreach ($data as $section => $value) { if (is_array($value)) { if (strpos($section, $this->nestSeparator) !== false) { - $section = explode($this->nestSeparator, $section, 2); - $config[$section[0]][$section[1]] = $this->processSection($value); + $sections = explode($this->nestSeparator, $section); + $config = array_merge_recursive($config, $this->buildNestedSection($sections, $value)); } else { $config[$section] = $this->processSection($value); } @@ -144,6 +144,27 @@ protected function process(array $data) return $config; } + /** + * Process a nested section + * + * @param array $sections + * @param mixed $value + * @return array + */ + private function buildNestedSection($sections, $value) + { + if(count($sections) == 0) { + return $this->processSection($value); + } + + $nestedSection = array(); + + $first = array_shift($sections); + $nestedSection[$first] = $this->buildNestedSection($sections, $value); + + return $nestedSection; + } + /** * Process a section. * diff --git a/tests/ZendTest/Config/Reader/IniTest.php b/tests/ZendTest/Config/Reader/IniTest.php index 66484b9100b..48838d6856d 100644 --- a/tests/ZendTest/Config/Reader/IniTest.php +++ b/tests/ZendTest/Config/Reader/IniTest.php @@ -87,17 +87,17 @@ public function testFromStringWithSection() public function testFromStringNested() { $ini = <<reader->fromString($ini); - $this->assertEquals($arrayIni['foo']['bar'], 'foobar'); - $this->assertEquals($arrayIni['foobar'][0], 'foobarArray'); - $this->assertEquals($arrayIni['foo']['baz'][0], 'foobaz1'); - $this->assertEquals($arrayIni['foo']['baz'][1], 'foobaz2'); + $this->assertEquals($arrayIni['bla']['foo']['bar'], 'foobar'); + $this->assertEquals($arrayIni['bla']['foobar'][0], 'foobarArray'); + $this->assertEquals($arrayIni['bla']['foo']['baz'][0], 'foobaz1'); + $this->assertEquals($arrayIni['bla']['foo']['baz'][1], 'foobaz2'); } }