blob: 85b295796adbf3c7dcec215e448ef32f1200bf4d [file] [log] [blame]
adminb0dd10f2006-08-25 17:25:49 +00001<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * Code Igniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
8 * @author Rick Ellis
9 * @copyright Copyright (c) 2006, pMachine, Inc.
10 * @license http://www.codeignitor.com/user_guide/license.html
11 * @link http://www.codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
19 * Code Igniter Config Class
20 *
21 * This class contains functions that enable config files to be managed
22 *
23 * @package CodeIgniter
24 * @subpackage Libraries
25 * @category Libraries
26 * @author Rick Ellis
27 * @link http://www.codeigniter.com/user_guide/libraries/config.html
28 */
29class CI_Config {
30
31 var $config = array();
32 var $is_loaded = array();
33
34 /**
35 * Constructor
36 *
37 * Sets the $config data from the primary config.php file as a class variable
38 *
39 * @access public
40 */
41 function CI_Config()
42 {
43 $this->config =& _get_config();
44 log_message('debug', "Config Class Initialized");
45 }
46 // END CI_Config()
47
48
49 // --------------------------------------------------------------------
50
51 /**
52 * Load Config File
53 *
54 * @access public
55 * @param string the config file name
56 * @return void
57 */
58 function load($file = '')
59 {
60 $file = ($file == '') ? 'config' : str_replace(EXT, '', $file);
61
62 if (in_array($file, $this->is_loaded))
63 {
64 return;
65 }
66
67 include_once(APPPATH.'config/'.$file.EXT);
68
69 if ( ! isset($config) OR ! is_array($config))
70 {
71 show_error('Your '.$file.EXT.' file does not appear to contain a valid configuration array.');
72 }
73
74 $this->config = array_merge($this->config, $config);
75
76 $this->is_loaded[] = $file;
77 unset($config);
78
79 log_message('debug', 'Config file loaded: config/'.$file.EXT);
80 }
81 // END load()
82
83 // --------------------------------------------------------------------
84
85 /**
86 * Fetch a config file item
87 *
88 * The second parameter allows a slash to be added to the end of
89 * the item, in the case of a path.
90 *
91 * @access public
92 * @param string the config item name
93 * @param bool
94 * @return string
95 */
96 function item($item, $slash = FALSE)
97 {
98 if ( ! isset($this->config[$item]))
99 {
100 return FALSE;
101 }
102
103 $pref = $this->config[$item];
104
105 if ($pref == '')
106 {
107 return $pref;
108 }
109
110 if ($slash !== FALSE AND ereg("/$", $pref) === FALSE)
111 {
112 $pref .= '/';
113 }
114
115 return $pref;
116 }
117 // END item()
118
119 // --------------------------------------------------------------------
120
121 /**
122 * Site URL
123 *
124 * @access public
125 * @param string the URI string
126 * @return string
127 */
128 function site_url($uri = '')
129 {
130 if (is_array($uri))
131 {
132 $uri = implode('/', $uri);
133 }
134
135 if ($uri == '')
136 {
137 return $this->item('base_url', 1).$this->item('index_page');
138 }
139 else
140 {
141 $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
142 return $this->item('base_url', 1).$this->item('index_page', 1).preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix;
143 }
144 }
145 // END site_url()
146
147 // --------------------------------------------------------------------
148
149 /**
150 * System URL
151 *
152 * @access public
153 * @return string
154 */
155 function system_url()
156 {
157 $x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH));
158 return $this->item('base_url', 1).end($x).'/';
159 }
160 // END system_url()
161
162 // --------------------------------------------------------------------
163
164 /**
165 * Set a config file item
166 *
167 * @access public
168 * @param string the config item key
169 * @param string the config item value
170 * @return void
171 */
172 function set_item($item, $value)
173 {
174 $this->config[$item] = $value;
175 }
176 // END set_item()
177
178}
179
180// END CI_Config class
181?>