$_val) { if (isset(${$_key})) { unset(${$_key}); } } } } } require_once('ISSO/Functions.php'); /** * Register Class * * This is an ISSO registry class. It holds all of the ISSO system variables as well * as serving as an object registry that is avaliable in the global scope to prevent * globalization of variables. There can only be one instance of this existing * at any given time. * * @author Blue Static * @copyright Copyright ©2002 - [#]year[#], Blue Static * @version $Revision$ * @package ISSO * */ class BSRegister { /** * Instance of this class * @var object */ private static $instance; /** * Application name * @var string */ private $application = 'Unknown ISSO Project'; /** * Application path * @var string */ private $appPath; /** * Application version * @var string */ private $appVersion; /** * Web path * @var string */ private $webPath; /** * Debug mode? * @var bool */ private $debug = false; /** * The master registry list * @var array */ private $registry = array(); /** * An array of debug messages * @var array */ private $debugInfo = array(); // ################################################################### /** * Constructor */ private function __construct() {} // ################################################################### /** * Returns the single instance of the register * * @param string A string param * * @return object BSRegister instance */ private static function _Instance() { if (!self::$instance) { self::$instance = new BSRegister(); } return self::$instance; } // ################################################################### /** * Sets the application name * * @param string Application name */ public static function SetApplication($name) { self::_Instance()->application = $name; } // ################################################################### /** * Gets the application name * * @return string Application name */ public static function GetApplication() { return self::_Instance()->application; } // ################################################################### /** * Sets the application's working path * * @param string Path */ public static function SetAppPath($path) { self::_Instance()->appPath = BSFunctions::FetchSourcePath($path); } // ################################################################### /** * Returns the path to the application * * @return string Application path */ public static function GetAppPath() { return self::_Instance()->appPath; } // ################################################################### /** * Sets the application version * * @param string Application version */ public static function SetAppVersion($vers) { self::_Instance()->appVersion = $vers; } // ################################################################### /** * Gets the application version * * @return string Application version */ public static function GetAppVersion() { return self::_Instance()->appVersion; } // ################################################################### /** * Sets the application's web path, which is the full path from the * server's web root * * @param string Path */ public static function SetWebPath($path) { self::_Instance()->webPath = BSFunctions::FetchSourcePath($path); } // ################################################################### /** * Returns the web path to the application * * @return string Application's web path */ public static function GetWebPath() { return self::_Instance()->webPath; } // ################################################################### /** * Sets the debug state * * @param bool Debug mode on? */ public static function SetDebug($debug) { self::_Instance()->debug = $debug; } // ################################################################### /** * Gets the debug mode state * * @return bool Debug mode on? */ public static function GetDebug() { return self::_Instance()->debug; } // ################################################################### /** * Registers a value in the master registry. You cannot overwrite * values. You must first unregister() them if you wish to do so. * * @param string Registry key * @param mixed Value to register */ public static function Register($key, $value) { if (isset(self::_Instance()->registry["$key"])) { throw new Exception('Cannot overwrite a key in the registry'); return; } self::_Instance()->registry["$key"] = $value; } // ################################################################### /** * Unregisters a value from the registry. This removes all traces of * it from this object. * * @param string Registry key */ public static function Unregister($key) { if (!isset(self::_Instance()->registry["$key"])) { throw new Exception('You cannot unregister a key that does not exist'); return; } unset(self::_Instance()->registry["$key"]); } // ################################################################### /** * This gets a value from the registry with a specific key * * @param string The key * * @return mixed Value in the registry for key */ public static function Get($key) { if (!isset(self::_Instance()->registry["$key"])) { throw new Exception('Cannot access the registry with a non-existent key'); return; } return self::_Instance()->registry["$key"]; } // ################################################################### /** * Returns the first object of a specified class type * * @param string Class name * * @return object Object in the registry of that type */ public static function GetType($class) { $class = 'BS' . $class; foreach (self::_Instance()->registry AS $key => $object) { if ($object instanceof $class) { return $object; } } } // ################################################################### /** * Returns the entire registry stack * * @return array Complete registry */ public static function GetAll() { return self::_Instance()->registry; } // ################################################################### /** * Adds a debug message to the array. This only works when debug mode * is enabled. * * @param string Debug message */ public static function Debug($msg) { if (self::_Instance()->debug) { self::_Instance()->debugInfo[] = $msg; } } // ################################################################### /** * Returns a '; foreach (self::_Instance()->debugInfo AS $notice) { $output .= ""; } return "$output"; } // ################################################################### /** * Loads the specified module. * * @param string Module name * * @return object Instantiated module */ public static function LoadModule($name) { if (BSRegister::GetDebug()) { include_once("ISSO/$name.php"); } else { @include_once("ISSO/$name.php"); } $class = "BS$name"; if (!class_exists($class)) { throw new Exception('Specifed module does not conform to the ISSO specification, or the class is missing'); return; } return new $class; } // ################################################################### /** * This function is used by other framework modules to check and see if * the passed array of module names have been loaded. If not, this will * throw an error informing the developer that the given modules are * required in order for the framework to work. * * @param array Array of module names to check for loadedness */ public static function RequiredModules($modules) { foreach ($modules AS $module) { if (self::GetType($module) == null AND !class_exists("BS$module")) { throw new Exception('The ' . $module . ' module is required in order to use this framework module'); } } } } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>