todo--
[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 /**
83 * Sets the application name
84 *
85 * @param string Application name
86 */
87 public function setApplication($name)
88 {
89 $this->application = $name;
90 }
91
92 // ###################################################################
93 /**
94 * Gets the application name
95 *
96 * @return string Application name
97 */
98 public function getApplication()
99 {
100 return $this->application;
101 }
102
103 // ###################################################################
104 /**
105 * Sets the application's working path
106 *
107 * @param string Path
108 */
109 public function setAppPath($path)
110 {
111 $this->appPath = BSFunctions::FetchSourcePath($path);
112 }
113
114 // ###################################################################
115 /**
116 * Returns the path to the application
117 *
118 * @return string Application path
119 */
120 public function getAppPath()
121 {
122 return $this->appPath;
123 }
124
125 // ###################################################################
126 /**
127 * Sets the application version
128 *
129 * @param string Application version
130 */
131 public function setAppVersion($vers)
132 {
133 $this->appVersion = $vers;
134 }
135
136 // ###################################################################
137 /**
138 * Gets the application version
139 *
140 * @return string Application version
141 */
142 public function getAppVersion()
143 {
144 return $this->appVersion;
145 }
146
147 // ###################################################################
148 /**
149 * Sets the application's web path, which is the full path from the
150 * server's web root
151 *
152 * @param string Path
153 */
154 public function setWebPath($path)
155 {
156 $this->webPath = BSFunctions::FetchSourcePath($path);
157 }
158
159 // ###################################################################
160 /**
161 * Returns the web path to the application
162 *
163 * @return string Application's web path
164 */
165 public function getWebPath()
166 {
167 return $this->webPath;
168 }
169
170 // ###################################################################
171 /**
172 * Sets the debug state
173 *
174 * @param bool Debug mode on?
175 */
176 public function setDebug($debug)
177 {
178 $this->debug = $debug;
179 }
180
181 // ###################################################################
182 /**
183 * Gets the debug mode state
184 *
185 * @return bool Debug mode on?
186 */
187 public function getDebug()
188 {
189 return $this->debug;
190 }
191
192 // ###################################################################
193 /**
194 * Registers a value in the master registry. You cannot overwrite
195 * values. You must first unregister() them if you wish to do so.
196 *
197 * @param string Registry key
198 * @param mixed Value to register
199 */
200 public function register($key, $value)
201 {
202 if (isset($this->registry["$key"]))
203 {
204 trigger_error('Cannot overwrite a key in the registry');
205 return;
206 }
207
208 $this->registry["$key"] = $value;
209 }
210
211 // ###################################################################
212 /**
213 * Unregisters a value from the registry. This removes all traces of
214 * it from this object.
215 *
216 * @param string Registry key
217 */
218 public function unregister($key)
219 {
220 if (!isset($this->registry["$key"]))
221 {
222 trigger_error('You cannot unregister a key that does not exist');
223 return;
224 }
225
226 unset($this->registry["$key"]);
227 }
228
229 // ###################################################################
230 /**
231 * This gets a value from the registry with a specific key
232 *
233 * @param string The key
234 *
235 * @return mixed Value in the registry for key
236 */
237 public function get($key)
238 {
239 if (!isset($this->registry["$key"]))
240 {
241 trigger_error('Cannot access the registry with a non-existent key');
242 return;
243 }
244
245 return $this->registry["$key"];
246 }
247
248 // ###################################################################
249 /**
250 * Returns the entire registry stack
251 *
252 * @return array Complete registry
253 */
254 public function getAll()
255 {
256 return $this->registry;
257 }
258 }
259
260 /*=====================================================================*\
261 || ###################################################################
262 || # $HeadURL$
263 || # $Id$
264 || ###################################################################
265 \*=====================================================================*/
266 ?>