$_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 == null) { self::$instance = new BSRegister(); set_error_handler(array(self::$instance, '_errorHandler')); } 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"])) { trigger_error('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"])) { trigger_error('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"])) { trigger_error('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)) { trigger_error('Specifed module does not conform to the ISSO specification, or the class is missing'); return; } return new $class; } // ################################################################### /** * Prints an ISSO message * * @param string The title of the message * @param string The content of the message * @param integer Type of message to be printed * @param bool Return the output? * @param bool Show the debug stack? * @param integer Message width * * @return mixed Output or null */ public static function Message($title, $message, $type, $return = false, $stack = true, $width = 500) { switch ($type) { // Message case 1: $prefix = 'Message'; $color = '#669900'; $font = '#000000'; break; // Warning case 2: $prefix = 'Warning'; $color = '#003399'; $font = '#FFFFFF'; break; case 3: $prefix = 'Error'; $color = '#990000'; $font = '#EFEFEF'; break; } echo "\n
\n"; echo "\n\n\t\n"; echo "\n\n\t\n"; if ($stack AND self::Instance()->getDebug()) { echo "\n\n\t\n"; } echo "\n
$prefix: $title
$message
Debug Stack:
";
			echo BSFunctions::FormatBacktrace(debug_backtrace());
			echo "
\n
\n"; } // ################################################################### /** * Custom error handler for ISSO; only handle E_WARNING, E_NOTICE, * E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE * * @param integer Error number * @param string Error message string * @param string File that contains the error * @param string The line number of the error * @param string The active symbol table at which point the error occurred */ public function _errorHandler($errno, $errstr, $errfile, $errline, $errcontext) { $level = ini_get('error_reporting'); switch ($errno) { // So we don't need to specify the error type in trigger_error(), all E_USER_NOTICEs // are fatal and automatically kill the script case E_USER_NOTICE: $title = 'Fatal'; $mode = 3; break; // A non-fatal but important warning case E_WARNING: $title = 'Warning'; $mode = 2; if (!($level & E_WARNING)) { return; } break; // A non-fatal notice that should all but be ignored unless in dev environments case E_NOTICE: case E_STRICT: $title = 'Notice'; $mode = 1; if (!($level & E_NOTICE)) { return; } break; case E_USER_WARNING: case E_USER_NOTICE: default: trigger_error('The only error types supported are E_USER_NOTICE (fatal), E_WARNING, and E_NOTICE'); break; } // change the file and line of the error so we aren't looking at the location of the trigger_error() $backtrace = debug_backtrace(); if ($backtrace[1]['function'] == 'trigger_error' AND isset($backtrace[2]['file'])) { $errfile = $backtrace[2]['file']; $errline = $backtrace[2]['line']; } $errstr .= " in $errfile on line $errline"; $errstr = str_replace(array(getcwd(), dirname(getcwd())), '', $errstr); self::Message($title, $errstr, $mode); if ($errno == E_USER_NOTICE) { exit; } } // ################################################################### /** * Creates a table that explains the error reporting levels and their * state */ public static function ExplainErrorReporting() { $levels = array( 'E_ERROR' => E_ERROR, 'E_WARNING' => E_WARNING, 'E_PARSE' => E_PARSE, 'E_NOTICE' => E_NOTICE, 'E_CORE_ERROR' => E_CORE_ERROR, 'E_CORE_WARNING' => E_CORE_WARNING, 'E_COMPILE_ERROR' => E_COMPILE_ERROR, 'E_COMPILE_WARNING' => E_COMPILE_WARNING, 'E_USER_ERROR' => E_USER_ERROR, 'E_USER_WARNING' => E_USER_WARNING, 'E_USER_NOTICE' => E_USER_NOTICE, 'E_ALL' => E_ALL, 'E_STRICT' => E_STRICT ); $table = ''; foreach ($levels AS $name => $value) { $table .= ' '; } $table .= '
' . $name . ' ' . (ini_get('error_reporting') & $value) . '
'; self::Message('Error Reporting', $table, 1); } // ################################################################### /** * 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) { trigger_error('The ' . $module . ' is required in order to use this framework module'); } } } } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>