| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- class Core_Config_INI {
- var $_config_file;
- var $_data;
- function __construct( $config_file ) {
- $this->_config_file = $config_file;
- $this->_data = null;
- }
- /**
- * @return an associative array on success, and FALSE on failure.
- */
- 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;
- }
- 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;
- }
- }//class
|