No longer use underscores in the API. This is a very breaking-heavy commit.
[isso.git] / Register.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework [#]issoversion[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 /**
23 * ISSO Registry (Register.php)
24 *
25 * @package ISSO
26 */
27
28 require_once('ISSO/Functions.php');
29
30 /**
31 * Register Class
32 *
33 * This is an ISSO registry class. It holds all of the ISSO system variables as well
34 * as serving as an object registry that is avaliable in the global scope to prevent
35 * globalization of variables.
36 *
37 * @author Blue Static
38 * @copyright Copyright ©2002 - [#]year[#], Blue Static
39 * @version $Revision$
40 * @package ISSO
41 *
42 */
43 class BSRegister
44 {
45 /**
46 * Application name
47 * @var string
48 */
49 private $application = 'Unknown ISSO Project';
50
51 /**
52 * Application path
53 * @var string
54 */
55 private $appPath;
56
57 /**
58 * Application version
59 * @var string
60 */
61 private $appVersion;
62
63 /**
64 * Web path
65 * @var string
66 */
67 private $webPath;
68
69 /**
70 * Debug mode?
71 * @var bool
72 */
73 private $debug = false;
74
75 /**
76 * The master registry list
77 * @var array
78 */
79 private $registry = array();
80
81 /**
82 * An array of debug messages
83 * @var array
84 */
85 private $debugInfo = array();
86
87 // ###################################################################
88 /**
89 * Sets the application name
90 *
91 * @param string Application name
92 */
93 public function setApplication($name)
94 {
95 $this->application = $name;
96 }
97
98 // ###################################################################
99 /**
100 * Gets the application name
101 *
102 * @return string Application name
103 */
104 public function getApplication()
105 {
106 return $this->application;
107 }
108
109 // ###################################################################
110 /**
111 * Sets the application's working path
112 *
113 * @param string Path
114 */
115 public function setAppPath($path)
116 {
117 $this->appPath = BSFunctions::FetchSourcePath($path);
118 }
119
120 // ###################################################################
121 /**
122 * Returns the path to the application
123 *
124 * @return string Application path
125 */
126 public function getAppPath()
127 {
128 return $this->appPath;
129 }
130
131 // ###################################################################
132 /**
133 * Sets the application version
134 *
135 * @param string Application version
136 */
137 public function setAppVersion($vers)
138 {
139 $this->appVersion = $vers;
140 }
141
142 // ###################################################################
143 /**
144 * Gets the application version
145 *
146 * @return string Application version
147 */
148 public function getAppVersion()
149 {
150 return $this->appVersion;
151 }
152
153 // ###################################################################
154 /**
155 * Sets the application's web path, which is the full path from the
156 * server's web root
157 *
158 * @param string Path
159 */
160 public function setWebPath($path)
161 {
162 $this->webPath = BSFunctions::FetchSourcePath($path);
163 }
164
165 // ###################################################################
166 /**
167 * Returns the web path to the application
168 *
169 * @return string Application's web path
170 */
171 public function getWebPath()
172 {
173 return $this->webPath;
174 }
175
176 // ###################################################################
177 /**
178 * Sets the debug state
179 *
180 * @param bool Debug mode on?
181 */
182 public function setDebug($debug)
183 {
184 $this->debug = $debug;
185 }
186
187 // ###################################################################
188 /**
189 * Gets the debug mode state
190 *
191 * @return bool Debug mode on?
192 */
193 public function getDebug()
194 {
195 return $this->debug;
196 }
197
198 // ###################################################################
199 /**
200 * Registers a value in the master registry. You cannot overwrite
201 * values. You must first unregister() them if you wish to do so.
202 *
203 * @param string Registry key
204 * @param mixed Value to register
205 */
206 public function register($key, $value)
207 {
208 if (isset($this->registry["$key"]))
209 {
210 trigger_error('Cannot overwrite a key in the registry');
211 return;
212 }
213
214 $this->registry["$key"] = $value;
215 }
216
217 // ###################################################################
218 /**
219 * Unregisters a value from the registry. This removes all traces of
220 * it from this object.
221 *
222 * @param string Registry key
223 */
224 public function unregister($key)
225 {
226 if (!isset($this->registry["$key"]))
227 {
228 trigger_error('You cannot unregister a key that does not exist');
229 return;
230 }
231
232 unset($this->registry["$key"]);
233 }
234
235 // ###################################################################
236 /**
237 * This gets a value from the registry with a specific key
238 *
239 * @param string The key
240 *
241 * @return mixed Value in the registry for key
242 */
243 public function get($key)
244 {
245 if (!isset($this->registry["$key"]))
246 {
247 trigger_error('Cannot access the registry with a non-existent key');
248 return;
249 }
250
251 return $this->registry["$key"];
252 }
253
254 // ###################################################################
255 /**
256 * Returns the entire registry stack
257 *
258 * @return array Complete registry
259 */
260 public function getAll()
261 {
262 return $this->registry;
263 }
264
265 // ###################################################################
266 /**
267 * Adds a debug message to the array. This only works when debug mode
268 * is enabled.
269 *
270 * @param string Debug message
271 */
272 public function debug($msg)
273 {
274 if ($this->debug)
275 {
276 $this->debugInfo[] = $msg;
277 }
278 }
279 }
280
281 /*=====================================================================*\
282 || ###################################################################
283 || # $HeadURL$
284 || # $Id$
285 || ###################################################################
286 \*=====================================================================*/
287 ?>