| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- class Core_Config_INI {
- var $_config_file;
- var $_data;
- public function __construct($config_file) {
- $this->_config_file = $config_file;
- $this->_data = null;
- }
- /**
- * @return an associative array on success, and FALSE on failure.
- */
- public function getData() {
- if ($this->_data === null) {// @see __construct()
- if (!file_exists($this->_config_file)) {
- $this->_data = false;
- trigger_error('config file not exists', E_USER_WARNING);
- } else {
- $this->_data = parse_ini_file($this->_config_file, true);// @return false if error
- }
- }
- return $this->_data;
- }
- public function get($key, $section = null) {
- $_data = $this->getData();
- if ($_data == false) {
- return false;
- }
- if (null != $section) {
- if (array_key_exists($section, $_data)) {
- if (array_key_exists($key, $_data[$section])) {
- return $_data[$section][$key];
- } else {
- trigger_error('config error: key('.$key.') not exists in section ('.$section.')', E_USER_NOTICE);
- }
- } else {
- trigger_error('config error: section not exists: ('.$section.')', E_USER_NOTICE);
- }
- }
- else {
- if (array_key_exists($key, $_data)) {
- return $_data[$key];
- } else {
- trigger_error('config error: key not exists ('.$key.')', E_USER_NOTICE);
- }
- }
- return false;
- }
- }
|