2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright ©2002-[#]year[#] Blue Static
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.
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
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 \*=====================================================================*/
23 * ISSO Registry (Register.php)
26 * ISSO_MT_START - Define the microtime() value at the top of your
27 * script and this will calculate the total execution
29 * SVN - Place SVN $Id keyword to get SVN revision information on output
34 // we need PHP 5.2.0 to run
35 if (!function_exists('array_fill_keys'))
37 print('You need PHP version 5.2.0 or newer to run ISSO');
41 // get rid of register_globals
42 if ((bool
)ini_get('register_globals') === true
)
44 $superglobals = array('_GET', '_COOKIE', '_FILES', '_POST', '_SERVER', '_ENV');
45 foreach ($superglobals AS $global)
47 if (is_array($
{$global}))
49 foreach ($
{$global} AS $_key => $_val)
60 require_once('ISSO/Functions.php');
65 * This is an ISSO registry class. It holds all of the ISSO system variables as well
66 * as serving as an object registry that is avaliable in the global scope to prevent
67 * globalization of variables. There can only be one instance of this existing
71 * @copyright Copyright ©2002 - [#]year[#], Blue Static
79 * Instance of this class
82 private static $instance;
88 private $application = 'Unknown ISSO Project';
112 private $debug = false
;
115 * The master registry list
118 private $registry = array();
121 * An array of debug messages
124 private $debugInfo = array();
126 // ###################################################################
130 private function __construct()
133 // ###################################################################
135 * Returns the single instance of the register
137 * @param string A string param
139 * @return object BSRegister instance
141 private static function _Instance()
143 if (!self
::$instance)
145 self
::$instance = new BSRegister();
147 return self
::$instance;
150 // ###################################################################
152 * Sets the application name
154 * @param string Application name
156 public static function SetApplication($name)
158 self
::_Instance()->application
= $name;
161 // ###################################################################
163 * Gets the application name
165 * @return string Application name
167 public static function GetApplication()
169 return self
::_Instance()->application
;
172 // ###################################################################
174 * Sets the application's working path
178 public static function SetAppPath($path)
180 self
::_Instance()->appPath
= BSFunctions
::FetchSourcePath($path);
183 // ###################################################################
185 * Returns the path to the application
187 * @return string Application path
189 public static function GetAppPath()
191 return self
::_Instance()->appPath
;
194 // ###################################################################
196 * Sets the application version
198 * @param string Application version
200 public static function SetAppVersion($vers)
202 self
::_Instance()->appVersion
= $vers;
205 // ###################################################################
207 * Gets the application version
209 * @return string Application version
211 public static function GetAppVersion()
213 return self
::_Instance()->appVersion
;
216 // ###################################################################
218 * Sets the application's web path, which is the full path from the
223 public static function SetWebPath($path)
225 self
::_Instance()->webPath
= BSFunctions
::FetchSourcePath($path);
228 // ###################################################################
230 * Returns the web path to the application
232 * @return string Application's web path
234 public static function GetWebPath()
236 return self
::_Instance()->webPath
;
239 // ###################################################################
241 * Sets the debug state
243 * @param bool Debug mode on?
245 public static function SetDebug($debug)
247 self
::_Instance()->debug
= $debug;
250 // ###################################################################
252 * Gets the debug mode state
254 * @return bool Debug mode on?
256 public static function GetDebug()
258 return self
::_Instance()->debug
;
261 // ###################################################################
263 * Registers a value in the master registry. You cannot overwrite
264 * values. You must first unregister() them if you wish to do so.
266 * @param string Registry key
267 * @param mixed Value to register
269 public static function Register($key, $value)
271 if (isset(self
::_Instance()->registry
["$key"]))
273 throw new Exception('Cannot overwrite a key in the registry');
277 self
::_Instance()->registry
["$key"] = $value;
280 // ###################################################################
282 * Unregisters a value from the registry. This removes all traces of
283 * it from this object.
285 * @param string Registry key
287 public static function Unregister($key)
289 if (!isset(self
::_Instance()->registry
["$key"]))
291 throw new Exception('You cannot unregister a key that does not exist');
295 unset(self
::_Instance()->registry
["$key"]);
298 // ###################################################################
300 * This gets a value from the registry with a specific key
302 * @param string The key
304 * @return mixed Value in the registry for key
306 public static function Get($key)
308 if (!isset(self
::_Instance()->registry
["$key"]))
310 throw new Exception('Cannot access the registry with a non-existent key');
314 return self
::_Instance()->registry
["$key"];
317 // ###################################################################
319 * Returns the first object of a specified class type
321 * @param string Class name
323 * @return object Object in the registry of that type
325 public static function GetType($class)
327 $class = 'BS' . $class;
328 foreach (self
::_Instance()->registry
AS $key => $object)
330 if ($object instanceof $class)
337 // ###################################################################
339 * Returns the entire registry stack
341 * @return array Complete registry
343 public static function GetAll()
345 return self
::_Instance()->registry
;
348 // ###################################################################
350 * Adds a debug message to the array. This only works when debug mode
353 * @param string Debug message
355 public static function Debug($msg)
357 if (self
::_Instance()->debug
)
359 self
::_Instance()->debugInfo
[] = $msg;
363 // ###################################################################
365 * Returns a <select> menu of all the debug notices
367 * @return string Debug list
369 public static function GetDebugList()
371 $output = '<select><option>Debug Notices (' . sizeof(self
::_Instance()->debugInfo
) . ')</option>';
372 foreach (self
::_Instance()->debugInfo
AS $notice)
374 $output .= "<option>--- $notice</option>";
376 return "$output</select>";
379 // ###################################################################
381 * Loads the specified module.
383 * @param string Module name
385 * @return object Instantiated module
387 public static function LoadModule($name)
389 if (BSRegister
::GetDebug())
391 include_once("ISSO/$name.php");
395 @include_once("ISSO/$name.php");
400 if (!class_exists($class))
402 throw new Exception('Specifed module does not conform to the ISSO specification, or the class is missing');
409 // ###################################################################
411 * This function is used by other framework modules to check and see if
412 * the passed array of module names have been loaded. If not, this will
413 * throw an error informing the developer that the given modules are
414 * required in order for the framework to work.
416 * @param array Array of module names to check for loadedness
418 public static function RequiredModules($modules)
420 foreach ($modules AS $module)
422 if (self
::GetType($module) == null
AND !class_exists("BS$module"))
424 throw new Exception('The ' . $module . ' module is required in order to use this framework module');
430 /*=====================================================================*\
431 || ###################################################################
434 || ###################################################################
435 \*=====================================================================*/