2010-11-28 17:54:32 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* IniFile
|
|
|
|
*
|
|
|
|
* PHP 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs.controller.components
|
|
|
|
* @since CakePHP(tm) v 2.0
|
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-11-29 01:27:45 +00:00
|
|
|
* Ini file configuration parser. Since IniFile uses parse_ini_file underneath,
|
|
|
|
* you should be aware that this class shares the same behavior, especially with
|
|
|
|
* regards to boolean and null values.
|
2010-11-28 17:54:32 +00:00
|
|
|
*
|
|
|
|
* @package cake.config
|
2010-11-29 01:27:45 +00:00
|
|
|
* @see http://php.net/parse_ini_file
|
2010-11-28 17:54:32 +00:00
|
|
|
*/
|
2010-11-29 00:58:59 +00:00
|
|
|
class IniFile implements ArrayAccess {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Values inside the ini file.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $_values = array();
|
2010-11-28 17:54:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Build and construct a new ini file parser, the parser will be a representation of the ini
|
|
|
|
* file as an object.
|
|
|
|
*
|
|
|
|
* @param string $filename Full path to the file to parse.
|
2010-11-29 01:27:45 +00:00
|
|
|
* @param string $section Only get one section.
|
2010-11-28 17:54:32 +00:00
|
|
|
*/
|
2010-11-29 01:27:45 +00:00
|
|
|
public function __construct($filename, $section = null) {
|
2010-11-29 00:58:59 +00:00
|
|
|
$contents = parse_ini_file($filename, true);
|
2010-11-29 01:27:45 +00:00
|
|
|
if (!empty($section) && isset($contents[$section])) {
|
|
|
|
$this->_values = $contents[$section];
|
|
|
|
} else {
|
|
|
|
$this->_values = $contents;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the contents of the ini file as a plain array.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function asArray() {
|
|
|
|
return $this->_values;
|
2010-11-29 00:58:59 +00:00
|
|
|
}
|
|
|
|
|
2010-11-29 01:27:45 +00:00
|
|
|
/**
|
|
|
|
* Part of ArrayAccess implementation.
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
*/
|
2010-11-29 00:58:59 +00:00
|
|
|
public function offsetExists($name) {
|
|
|
|
return isset($this->_values[$name]);
|
|
|
|
}
|
2010-11-29 01:27:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Part of ArrayAccess implementation.
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
*/
|
2010-11-29 00:58:59 +00:00
|
|
|
public function offsetGet($name) {
|
|
|
|
if (!isset($this->_values[$name])) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return $this->_values[$name];
|
|
|
|
}
|
2010-11-29 01:27:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Part of ArrayAccess implementation.
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
*/
|
2010-11-29 00:58:59 +00:00
|
|
|
public function offsetSet($name, $value) {
|
2010-11-29 01:27:45 +00:00
|
|
|
throw new LogicException('You cannot modify an IniFile parse result.');
|
2010-11-29 00:58:59 +00:00
|
|
|
}
|
2010-11-29 01:27:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Part of ArrayAccess implementation.
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
*/
|
2010-11-29 00:58:59 +00:00
|
|
|
public function offsetUnset($name) {
|
|
|
|
unset($this->_values[$name]);
|
2010-11-28 17:54:32 +00:00
|
|
|
}
|
|
|
|
}
|