Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Issue #3222 - Added suport for multi-level nested ini config variables #3236

Closed
wants to merge 2 commits into from

3 participants

@robertboloc

Multi-level ini config variables can now be parsed

Issue #3222

@robertboloc

The Travis build fail seems to be unrelated to this fix.

library/Zend/Config/Reader/Ini.php
@@ -145,6 +145,27 @@ protected function process(array $data)
}
/**
+ * 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);
+ } else {

remove 'else' because already return early.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/3236'
Close #3236
6c03f92
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/3236' into develop
Forward port #3236
2833714
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 16, 2012
  1. @robertboloc
Commits on Dec 17, 2012
  1. @robertboloc
This page is out of date. Refresh to see the latest.
View
25 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);
}
@@ -145,6 +145,27 @@ protected function process(array $data)
}
/**
+ * 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.
*
* @param array $section
View
16 tests/ZendTest/Config/Reader/IniTest.php
@@ -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');
}
}
Something went wrong with that request. Please try again.