$_val) { if (isset(${$_key})) { unset(${$_key}); } } } } } require_once('ISSO/Functions.php'); /** * Application Class * * This is an ISSO application 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 (c)2002 - 2007, Blue Static * @package ISSO * */ class BSApp { /** * 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 = null; /** * An array of debug messages * @var array */ private $debugInfo = array(); // ################################################################### /** * Constructor */ private function __construct() { $this->registry = new BSVariableRegistry(); } // ################################################################### /** * Returns the single instance of the register * * @param string A string param * * @return object BSApp instance */ private static function _Instance() { if (!self::$instance) { self::$instance = new BSApp(); } 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; } // ################################################################### /** * Returns the registry object without it ever being able to be cleared * or unset * * @return StdClass */ public static function Registry() { 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 (self::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::Registry()->getType($module) == null) { throw new Exception('The ' . $module . ' module is required in order to use this framework module'); } } } } /** * Variable Registry * * This class can be used to store unlimited number of properties. It is a (make believe) * inner class to BSApp and cannot be instantiated outside of it. * * @author Blue Static * @copyright Copyright (c)2002 - 2007, Blue Static * @version $Id$ * @package ISSO * */ class BSVariableRegistry { // ################################################################### /** * Constructor: only able to be called by BSApp */ public function __construct() { $bt = debug_backtrace(); if (!isset($bt[1]['class']) OR $bt[1]['class'] != 'BSApp') { exit('You cannot instantiate ' . __CLASS__ . ' directly. It is an internal class.'); } } // ################################################################### /** * If you try and get a non-existent property, throw a new exception */ public function __get($name) { throw new Exception('Failed to get nonexistent property "' . $name . '"'); } // ################################################################### /** * Returns the first value of the given type in the variable registry * * @return mixed */ public function getType($class) { $class = 'BS' . $class; foreach ($this AS $object) { if ($object instanceof $class) { return $object; } } } // ################################################################### /** * Returns all the objects in the registry by iterating over it * * @return array */ public function allObjects() { $registry = array(); foreach ($this AS $key => $value) { $registry[$key] = $value; } return $registry; } } ?>