Support to read ini files without section in IniReader.

This commit is contained in:
Juan Basso 2011-01-23 19:26:13 -02:00
parent c970770c8d
commit 55c557d5a1
3 changed files with 24 additions and 1 deletions

View file

@ -77,7 +77,12 @@ class IniReader implements ConfigReaderInterface {
} else {
$values = array();
foreach ($contents as $section => $attribs) {
if (is_array($attribs)) {
$values[$section] = $this->_parseNestedValues($attribs);
} else {
$parse = $this->_parseNestedValues(array($attribs));
$values[$section] = array_shift($parse);
}
}
}
return $values;

View file

@ -64,6 +64,22 @@ class IniReaderTest extends CakeTestCase {
$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.
*

View file

@ -0,0 +1,2 @@
some_key = some_value
bool_key = 1