]>
src.bluestatic.org Git - isso.git/blob - Register.php
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 = null;
121 * An array of debug messages
124 private $debugInfo = array();
126 // ###################################################################
130 private function __construct()
132 $this->registry
= new BSVariableRegistry();
135 // ###################################################################
137 * Returns the single instance of the register
139 * @param string A string param
141 * @return object BSRegister instance
143 private static function _Instance()
145 if (!self
::$instance)
147 self
::$instance = new BSRegister();
149 return self
::$instance;
152 // ###################################################################
154 * Sets the application name
156 * @param string Application name
158 public static function SetApplication($name)
160 self
::_Instance()->application
= $name;
163 // ###################################################################
165 * Gets the application name
167 * @return string Application name
169 public static function GetApplication()
171 return self
::_Instance()->application
;
174 // ###################################################################
176 * Sets the application's working path
180 public static function SetAppPath($path)
182 self
::_Instance()->appPath
= BSFunctions
::FetchSourcePath($path);
185 // ###################################################################
187 * Returns the path to the application
189 * @return string Application path
191 public static function GetAppPath()
193 return self
::_Instance()->appPath
;
196 // ###################################################################
198 * Sets the application version
200 * @param string Application version
202 public static function SetAppVersion($vers)
204 self
::_Instance()->appVersion
= $vers;
207 // ###################################################################
209 * Gets the application version
211 * @return string Application version
213 public static function GetAppVersion()
215 return self
::_Instance()->appVersion
;
218 // ###################################################################
220 * Sets the application's web path, which is the full path from the
225 public static function SetWebPath($path)
227 self
::_Instance()->webPath
= BSFunctions
::FetchSourcePath($path);
230 // ###################################################################
232 * Returns the web path to the application
234 * @return string Application's web path
236 public static function GetWebPath()
238 return self
::_Instance()->webPath
;
241 // ###################################################################
243 * Sets the debug state
245 * @param bool Debug mode on?
247 public static function SetDebug($debug)
249 self
::_Instance()->debug
= $debug;
252 // ###################################################################
254 * Gets the debug mode state
256 * @return bool Debug mode on?
258 public static function GetDebug()
260 return self
::_Instance()->debug
;
263 // ###################################################################
265 * Returns the registry object without it ever being able to be cleared
270 public static function Registry()
272 return self
::_Instance()->registry
;
275 // ###################################################################
277 * Adds a debug message to the array. This only works when debug mode
280 * @param string Debug message
282 public static function Debug($msg)
284 if (self
::_Instance()->debug
)
286 self
::_Instance()->debugInfo
[] = $msg;
290 // ###################################################################
292 * Returns a <select> menu of all the debug notices
294 * @return string Debug list
296 public static function GetDebugList()
298 $output = '<select><option>Debug Notices (' . sizeof(self
::_Instance()->debugInfo
) . ')</option>';
299 foreach (self
::_Instance()->debugInfo
AS $notice)
301 $output .= "<option>--- $notice</option>";
303 return "$output</select>";
306 // ###################################################################
308 * Loads the specified module.
310 * @param string Module name
312 * @return object Instantiated module
314 public static function LoadModule($name)
316 if (BSRegister
::GetDebug())
318 include_once("ISSO/$name.php");
322 @include_once("ISSO/$name.php");
327 if (!class_exists($class))
329 throw new Exception('Specifed module does not conform to the ISSO specification, or the class is missing');
336 // ###################################################################
338 * This function is used by other framework modules to check and see if
339 * the passed array of module names have been loaded. If not, this will
340 * throw an error informing the developer that the given modules are
341 * required in order for the framework to work.
343 * @param array Array of module names to check for loadedness
345 public static function RequiredModules($modules)
347 foreach ($modules AS $module)
349 if (self::GetType($module) == null AND !class_exists("BS
$module"))
351 throw new Exception('The ' . $module . ' module is required in order to use this framework module');
362 * This class can be used to store unlimited number of properties. It is a (make believe)
363 * inner class to BSRegister and cannot be instantiated outside of it.
365 * @author Blue Static
366 * @copyright Copyright (c)2002 - [#]year[#], Blue Static
371 class BSVariableRegistry
373 // ###################################################################
375 * Constructor: only able to be called by BSRegister
377 public function __construct()
379 $bt = debug_backtrace();
380 if (!isset($bt[1]['class']) OR $bt[1]['class'] != 'BSRegister')
382 exit('You cannot instantiate ' . __CLASS__
. ' directly. It is an internal class.');
386 // ###################################################################
388 * If you try and get a non-existent property, throw a new exception
390 public function __get($name)
392 throw new Exception('Failed to get nonexistent property "' . $name . '"');
395 // ###################################################################
397 * Returns the first value of the given type in the variable registry
401 public function getType($class)
403 $class = 'BS' . $class;
404 foreach ($this AS $object)
406 if ($object instanceof $class)
413 // ###################################################################
415 * Returns all the objects in the registry by iterating over it
419 public function allObjects()
422 foreach ($this AS $key => $value)
424 $registry[$key] = $value;
430 /*=====================================================================*\
431 || ###################################################################
434 || ###################################################################
435 \*=====================================================================*/