1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
5 * An open source application development framework for PHP 5.1.6 or newer
8 * @author ExpressionEngine Dev Team
9 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
10 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
16 // ------------------------------------------------------------------------
19 * CodeIgniter Config Class
21 * This class contains functions that enable config files to be managed
23 * @package CodeIgniter
24 * @subpackage Libraries
26 * @author ExpressionEngine Dev Team
27 * @link http://codeigniter.com/user_guide/libraries/config.html
31 var $config = array();
32 var $is_loaded = array();
33 var $_config_paths = array(APPPATH);
38 * Sets the $config data from the primary config.php file as a class variable
41 * @param string the config file name
42 * @param boolean if configuration values should be loaded into their own section
43 * @param boolean true if errors should just return false, false if an error message should be displayed
44 * @return boolean if the file was successfully loaded or not
46 function __construct()
48 $this->config =& get_config();
49 log_message('debug', "Config Class Initialized");
51 // Set the base_url automatically if none was provided
52 if ($this->config['base_url'] == '')
54 if (isset($_SERVER['HTTP_HOST']))
56 $base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
57 $base_url .= '://'. $_SERVER['HTTP_HOST'];
58 $base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
63 $base_url = 'http://localhost/';
66 $this->set_item('base_url', $base_url);
70 // --------------------------------------------------------------------
76 * @param string the config file name
77 * @param boolean if configuration values should be loaded into their own section
78 * @param boolean true if errors should just return false, false if an error message should be displayed
79 * @return boolean if the file was loaded correctly
81 function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
83 $file = ($file == '') ? 'config' : str_replace(EXT, '', $file);
87 foreach ($this->_config_paths as $path)
89 $check_locations = defined('ENVIRONMENT')
90 ? array(ENVIRONMENT.'/'.$file, $file)
93 foreach ($check_locations as $location)
95 $file_path = $path.'config/'.$location.EXT;
97 if (in_array($file_path, $this->is_loaded, TRUE))
103 if (file_exists($file_path))
110 if ($found === FALSE)
117 if ( ! isset($config) OR ! is_array($config))
119 if ($fail_gracefully === TRUE)
123 show_error('Your '.$file_path.' file does not appear to contain a valid configuration array.');
126 if ($use_sections === TRUE)
128 if (isset($this->config[$file]))
130 $this->config[$file] = array_merge($this->config[$file], $config);
134 $this->config[$file] = $config;
139 $this->config = array_merge($this->config, $config);
142 $this->is_loaded[] = $file_path;
146 log_message('debug', 'Config file loaded: '.$file_path);
149 if ($loaded === FALSE)
151 if ($fail_gracefully === TRUE)
155 show_error('The configuration file '.$file.EXT.' does not exist.');
161 // --------------------------------------------------------------------
164 * Fetch a config file item
168 * @param string the config item name
169 * @param string the index name
173 function item($item, $index = '')
177 if ( ! isset($this->config[$item]))
182 $pref = $this->config[$item];
186 if ( ! isset($this->config[$index]))
191 if ( ! isset($this->config[$index][$item]))
196 $pref = $this->config[$index][$item];
202 // --------------------------------------------------------------------
205 * Fetch a config file item - adds slash after item
207 * The second parameter allows a slash to be added to the end of
208 * the item, in the case of a path.
211 * @param string the config item name
215 function slash_item($item)
217 if ( ! isset($this->config[$item]))
222 return rtrim($this->config[$item], '/').'/';
225 // --------------------------------------------------------------------
231 * @param string the URI string
234 function site_url($uri = '')
238 return $this->slash_item('base_url').$this->item('index_page');
241 if ($this->item('enable_query_strings') == FALSE)
245 $uri = implode('/', $uri);
248 $index = $this->item('index_page') == '' ? '' : $this->slash_item('index_page');
249 $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
250 return $this->slash_item('base_url').$index.trim($uri, '/').$suffix;
258 foreach ($uri as $key => $val)
260 $prefix = ($i == 0) ? '' : '&';
261 $str .= $prefix.$key.'='.$val;
268 return $this->slash_item('base_url').$this->item('index_page').'?'.$uri;
272 // --------------------------------------------------------------------
280 function system_url()
282 $x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH));
283 return $this->slash_item('base_url').end($x).'/';
286 // --------------------------------------------------------------------
289 * Set a config file item
292 * @param string the config item key
293 * @param string the config item value
296 function set_item($item, $value)
298 $this->config[$item] = $value;
301 // --------------------------------------------------------------------
306 * This function is called by the front controller (CodeIgniter.php)
307 * after the Config class is instantiated. It permits config items
308 * to be assigned or overriden by variables contained in the index.php file
314 function _assign_to_config($items = array())
316 if (is_array($items))
318 foreach ($items as $key => $val)
320 $this->set_item($key, $val);
326 // END CI_Config class
328 /* End of file Config.php */
329 /* Location: ./system/core/Config.php */