Skip to content

Commit

Permalink
Support to read ini files without section in IniReader.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbasso committed Jan 23, 2011
1 parent c970770 commit 55c557d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cake/libs/config/ini_reader.php
Expand Up @@ -77,7 +77,12 @@ public function read($file) {
} else {
$values = array();
foreach ($contents as $section => $attribs) {
$values[$section] = $this->_parseNestedValues($attribs);
if (is_array($attribs)) {
$values[$section] = $this->_parseNestedValues($attribs);
} else {
$parse = $this->_parseNestedValues(array($attribs));
$values[$section] = array_shift($parse);
}
}
}
return $values;
Expand Down
16 changes: 16 additions & 0 deletions cake/tests/cases/libs/config/ini_reader.test.php
Expand Up @@ -64,6 +64,22 @@ function testReadingOnlyOneSection() {
$this->assertEquals('administrators', $config['groups']);
}

/**
* test without section
*
* @return void
*/
public function testReadingWithoutSection() {
$reader = new IniReader($this->path);
$config = $reader->read('no_section.ini');

$expected = array(
'some_key' => 'some_value',
'bool_key' => true
);
$this->assertEquals($config, $expected);
}

/**
* test that names with .'s get exploded into arrays.
*
Expand Down
2 changes: 2 additions & 0 deletions cake/tests/test_app/config/no_section.ini
@@ -0,0 +1,2 @@
some_key = some_value
bool_key = 1

0 comments on commit 55c557d

Please sign in to comment.