diff --git a/cake/libs/config/ini_file.php b/cake/libs/config/ini_file.php index cb5c8df73..e31218bd0 100644 --- a/cake/libs/config/ini_file.php +++ b/cake/libs/config/ini_file.php @@ -23,7 +23,14 @@ * * @package cake.config */ -class IniFile { +class IniFile implements ArrayAccess { + +/** + * Values inside the ini file. + * + * @var array + */ + protected $_values = array(); /** * Build and construct a new ini file parser, the parser will be a representation of the ini @@ -32,6 +39,26 @@ class IniFile { * @param string $filename Full path to the file to parse. */ public function __construct($filename) { - + $contents = parse_ini_file($filename, true); + $this->_values = $contents; + } + + public function offsetExists($name) { + return isset($this->_values[$name]); + } + + public function offsetGet($name) { + if (!isset($this->_values[$name])) { + return null; + } + return $this->_values[$name]; + } + + public function offsetSet($name, $value) { + $this->_values[$name] = $value; + } + + public function offsetUnset($name) { + unset($this->_values[$name]); } } \ No newline at end of file diff --git a/cake/tests/cases/libs/config/ini_file.test.php b/cake/tests/cases/libs/config/ini_file.test.php index c41b74203..56535dc57 100644 --- a/cake/tests/cases/libs/config/ini_file.test.php +++ b/cake/tests/cases/libs/config/ini_file.test.php @@ -4,6 +4,11 @@ App::import('Core', 'config/IniFile'); class IniFileTest extends CakeTestCase { +/** + * The test file that will be read. + * + * @var string + */ var $file; /** @@ -15,6 +20,7 @@ class IniFileTest extends CakeTestCase { parent::setup(); $this->file = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config'. DS . 'acl.ini.php'; } + /** * test constrction * @@ -22,6 +28,9 @@ class IniFileTest extends CakeTestCase { */ function testConstruct() { $config = new IniFile($this->file); - $this->assertTrue(isset($config->admin)); + + $this->assertTrue(isset($config['admin'])); + $this->assertTrue(isset($config['paul']['groups'])); + $this->assertEquals('ads', $config['admin']['deny']); } } \ No newline at end of file