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
32
* List of all loaded config values
36
var $config = array();
38
* List of all loaded config files
42
var $is_loaded = array();
44
* List of paths to search when trying to load a config file
48
var $_config_paths = array(APPPATH);
53
* Sets the $config data from the primary config.php file as a class variable
56
* @param string the config file name
57
* @param boolean if configuration values should be loaded into their own section
58
* @param boolean true if errors should just return false, false if an error message should be displayed
59
* @return boolean if the file was successfully loaded or not
61
function __construct()
63
$this->config =& get_config();
64
log_message('debug', "Config Class Initialized");
66
// Set the base_url automatically if none was provided
67
if ($this->config['base_url'] == '')
69
if (isset($_SERVER['HTTP_HOST']))
71
$base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
72
$base_url .= '://'. $_SERVER['HTTP_HOST'];
73
$base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
78
$base_url = 'http://localhost/';
81
$this->set_item('base_url', $base_url);
85
// --------------------------------------------------------------------
91
* @param string the config file name
92
* @param boolean if configuration values should be loaded into their own section
93
* @param boolean true if errors should just return false, false if an error message should be displayed
94
* @return boolean if the file was loaded correctly
96
function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
98
$file = ($file == '') ? 'config' : str_replace('.php', '', $file);
102
$check_locations = defined('ENVIRONMENT')
103
? array(ENVIRONMENT.'/'.$file, $file)
106
foreach ($this->_config_paths as $path)
108
foreach ($check_locations as $location)
110
$file_path = $path.'config/'.$location.'.php';
112
if (in_array($file_path, $this->is_loaded, TRUE))
118
if (file_exists($file_path))
125
if ($found === FALSE)
132
if ( ! isset($config) OR ! is_array($config))
134
if ($fail_gracefully === TRUE)
138
show_error('Your '.$file_path.' file does not appear to contain a valid configuration array.');
141
if ($use_sections === TRUE)
143
if (isset($this->config[$file]))
145
$this->config[$file] = array_merge($this->config[$file], $config);
149
$this->config[$file] = $config;
154
$this->config = array_merge($this->config, $config);
157
$this->is_loaded[] = $file_path;
161
log_message('debug', 'Config file loaded: '.$file_path);
165
if ($loaded === FALSE)
167
if ($fail_gracefully === TRUE)
171
show_error('The configuration file '.$file.'.php does not exist.');
177
// --------------------------------------------------------------------
180
* Fetch a config file item
184
* @param string the config item name
185
* @param string the index name
189
function item($item, $index = '')
193
if ( ! isset($this->config[$item]))
198
$pref = $this->config[$item];
202
if ( ! isset($this->config[$index]))
207
if ( ! isset($this->config[$index][$item]))
212
$pref = $this->config[$index][$item];
218
// --------------------------------------------------------------------
221
* Fetch a config file item - adds slash after item (if item is not empty)
224
* @param string the config item name
228
function slash_item($item)
230
if ( ! isset($this->config[$item]))
234
if( trim($this->config[$item]) == '')
239
return rtrim($this->config[$item], '/').'/';
242
// --------------------------------------------------------------------
246
* Returns base_url . index_page [. uri_string]
249
* @param string the URI string
252
function site_url($uri = '')
256
return $this->slash_item('base_url').$this->item('index_page');
259
if ($this->item('enable_query_strings') == FALSE)
261
$suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
262
return $this->slash_item('base_url').$this->slash_item('index_page').$this->_uri_string($uri).$suffix;
266
return $this->slash_item('base_url').$this->item('index_page').'?'.$this->_uri_string($uri);
270
// -------------------------------------------------------------
274
* Returns base_url [. uri_string]
280
function base_url($uri = '')
282
return $this->slash_item('base_url').ltrim($this->_uri_string($uri), '/');
285
// -------------------------------------------------------------
288
* Build URI string for use in Config::site_url() and Config::base_url()
294
protected function _uri_string($uri)
296
if ($this->item('enable_query_strings') == FALSE)
300
$uri = implode('/', $uri);
302
$uri = trim($uri, '/');
310
foreach ($uri as $key => $val)
312
$prefix = ($i == 0) ? '' : '&';
313
$str .= $prefix.$key.'='.$val;
322
// --------------------------------------------------------------------
330
function system_url()
332
$x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH));
333
return $this->slash_item('base_url').end($x).'/';
336
// --------------------------------------------------------------------
339
* Set a config file item
342
* @param string the config item key
343
* @param string the config item value
346
function set_item($item, $value)
348
$this->config[$item] = $value;
351
// --------------------------------------------------------------------
356
* This function is called by the front controller (CodeIgniter.php)
357
* after the Config class is instantiated. It permits config items
358
* to be assigned or overriden by variables contained in the index.php file
364
function _assign_to_config($items = array())
366
if (is_array($items))
368
foreach ($items as $key => $val)
370
$this->set_item($key, $val);
376
// END CI_Config class
378
/* End of file Config.php */
379
/* Location: ./system/core/Config.php */