Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/3236' into develop
Browse files Browse the repository at this point in the history
Forward port #3236
  • Loading branch information
weierophinney committed Dec 18, 2012
2 parents e044281 + b2b7486 commit 0de645c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
25 changes: 23 additions & 2 deletions library/Zend/Config/Reader/Ini.php
Expand Up @@ -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);
}
Expand All @@ -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.
*
Expand Down
16 changes: 8 additions & 8 deletions tests/ZendTest/Config/Reader/IniTest.php
Expand Up @@ -87,17 +87,17 @@ public function testFromStringWithSection()
public function testFromStringNested()
{
$ini = <<<ECS
foo.bar = foobar
foobar[] = foobarArray
foo.baz[] = foobaz1
foo.baz[] = foobaz2
bla.foo.bar = foobar
bla.foobar[] = foobarArray
bla.foo.baz[] = foobaz1
bla.foo.baz[] = foobaz2
ECS;

$arrayIni = $this->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');
}
}

0 comments on commit 0de645c

Please sign in to comment.