From 55c557d5a154e1880a0191c1a8305697fe51713e Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Sun, 23 Jan 2011 19:26:13 -0200 Subject: [PATCH] Support to read ini files without section in IniReader. --- cake/libs/config/ini_reader.php | 7 ++++++- cake/tests/cases/libs/config/ini_reader.test.php | 16 ++++++++++++++++ cake/tests/test_app/config/no_section.ini | 2 ++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 cake/tests/test_app/config/no_section.ini diff --git a/cake/libs/config/ini_reader.php b/cake/libs/config/ini_reader.php index 915bf9498..e20f8dcfb 100644 --- a/cake/libs/config/ini_reader.php +++ b/cake/libs/config/ini_reader.php @@ -77,7 +77,12 @@ class IniReader implements ConfigReaderInterface { } 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; diff --git a/cake/tests/cases/libs/config/ini_reader.test.php b/cake/tests/cases/libs/config/ini_reader.test.php index 2fb8eb2dd..3db8bb942 100644 --- a/cake/tests/cases/libs/config/ini_reader.test.php +++ b/cake/tests/cases/libs/config/ini_reader.test.php @@ -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. * diff --git a/cake/tests/test_app/config/no_section.ini b/cake/tests/test_app/config/no_section.ini new file mode 100644 index 000000000..6e6fbb7a0 --- /dev/null +++ b/cake/tests/test_app/config/no_section.ini @@ -0,0 +1,2 @@ +some_key = some_value +bool_key = 1