Added initial BSRegister class
[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 // TODO - rename
29 require_once('ISSO/Functions2.php');
30
31 /**
32 * Register Class
33 *
34 * This is an ISSO registry class. It holds all of the ISSO system variables as well
35 * as serving as an object registry that is avaliable in the global scope to prevent
36 * globalization of variables.
37 *
38 * @author Blue Static
39 * @copyright Copyright ©2002 - [#]year[#], Blue Static
40 * @version $Revision$
41 * @package ISSO
42 *
43 */
44 class BSRegister
45 {
46 /**
47 * Application name
48 * @var string
49 */
50 private $application = 'Unknown ISSO Project';
51
52 /**
53 * Application path
54 * @var string
55 */
56 private $appPath;
57
58 /**
59 * Application version
60 * @var string
61 */
62 private $appVersion;
63
64 /**
65 * Web path
66 * @var string
67 */
68 private $webPath;
69
70 /**
71 * Debug mode?
72 * @var bool
73 */
74 private $debug = false;
75
76 /**
77 * The master registry list
78 * @var array
79 */
80 private $registry = array();
81
82 // ###################################################################
83 /**
84 * Sets the application name
85 *
86 * @param string Application name
87 */
88 public function setApplication($name)
89 {
90 $this->application = $name;
91 }
92
93 // ###################################################################
94 /**
95 * Gets the application name
96 *
97 * @return string Application name
98 */
99 public function getApplication()
100 {
101 return $this->application;
102 }
103
104 // ###################################################################
105 /**
106 * Sets the application's working path
107 *
108 * @param string Path
109 */
110 public function setAppPath($path)
111 {
112 $this->appPath = BSFunctions::FetchSourcePath($path);
113 }
114
115 // ###################################################################
116 /**
117 * Returns the path to the application
118 *
119 * @return string Application path
120 */
121 public function getAppPath()
122 {
123 return $this->appPath;
124 }
125
126 // ###################################################################
127 /**
128 * Sets the application version
129 *
130 * @param string Application version
131 */
132 public function setAppVersion($vers)
133 {
134 $this->appVersion = $vers;
135 }
136
137 // ###################################################################
138 /**
139 * Gets the application version
140 *
141 * @return string Application version
142 */
143 public function getAppVersion()
144 {
145 return $this->appVersion;
146 }
147
148 // ###################################################################
149 /**
150 * Sets the application's web path, which is the full path from the
151 * server's web root
152 *
153 * @param string Path
154 */
155 public function setWebPath($path)
156 {
157 $this->webPath = BSFunctions::FetchSourcePath($path);
158 }
159
160 // ###################################################################
161 /**
162 * Returns the web path to the application
163 *
164 * @return string Application's web path
165 */
166 public function getWebPath()
167 {
168 return $this->webPath;
169 }
170
171 // ###################################################################
172 /**
173 * Sets the debug state
174 *
175 * @param bool Debug mode on?
176 */
177 public function setDebug($debug)
178 {
179 $this->debug = $debug;
180 }
181
182 // ###################################################################
183 /**
184 * Gets the debug mode state
185 *
186 * @return bool Debug mode on?
187 */
188 public function getDebug()
189 {
190 return $this->debug;
191 }
192
193 // ###################################################################
194 /**
195 * Registers a value in the master registry. You cannot overwrite
196 * values. You must first unregister() them if you wish to do so.
197 *
198 * @param string Registry key
199 * @param mixed Value to register
200 */
201 public function register($key, $value)
202 {
203 if (isset($this->registry["$key"]))
204 {
205 throw new Exception('Cannot overwrite a key in the registry');
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 throw new Exception('You cannot unregister a key that does not exist');
223 }
224
225 unset($this->registry["$key"]);
226 }
227
228 // ###################################################################
229 /**
230 * This gets a value from the registry with a specific key
231 *
232 * @param string The key
233 *
234 * @return mixed Value in the registry for key
235 */
236 public function get($key)
237 {
238 if (!isset($this->registry["$key"]))
239 {
240 throw new Exception('Cannot access the registry with a non-existent key');
241 }
242
243 return $this->registry["$key"];
244 }
245
246 // ###################################################################
247 /**
248 * Returns the entire registry stack
249 *
250 * @return array Complete registry
251 */
252 public function getAll()
253 {
254 return $this->registry;
255 }
256 }
257
258 /*=====================================================================*\
259 || ###################################################################
260 || # $HeadURL$
261 || # $Id$
262 || ###################################################################
263 \*=====================================================================*/
264 ?>