mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-17 06:59:51 +00:00
Adding very naive implementation of an ini file parser.
This commit is contained in:
parent
9d3b3a72ce
commit
071cd9b477
2 changed files with 39 additions and 3 deletions
|
@ -23,7 +23,14 @@
|
||||||
*
|
*
|
||||||
* @package cake.config
|
* @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
|
* 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.
|
* @param string $filename Full path to the file to parse.
|
||||||
*/
|
*/
|
||||||
public function __construct($filename) {
|
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]);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,6 +4,11 @@ App::import('Core', 'config/IniFile');
|
||||||
|
|
||||||
class IniFileTest extends CakeTestCase {
|
class IniFileTest extends CakeTestCase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The test file that will be read.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
var $file;
|
var $file;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,6 +20,7 @@ class IniFileTest extends CakeTestCase {
|
||||||
parent::setup();
|
parent::setup();
|
||||||
$this->file = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config'. DS . 'acl.ini.php';
|
$this->file = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config'. DS . 'acl.ini.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test constrction
|
* test constrction
|
||||||
*
|
*
|
||||||
|
@ -22,6 +28,9 @@ class IniFileTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testConstruct() {
|
function testConstruct() {
|
||||||
$config = new IniFile($this->file);
|
$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']);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue