]>
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 PHP5 to run
35 if (!function_exists('stripos'))
37 trigger_error('You need PHP version 5.0.0 or newer to run ISSO', E_USER_ERROR
);
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() {}
132 // ###################################################################
134 * Returns the single instance of the register
136 * @param string A string param
138 * @return object BSRegister instance
140 private static function _Instance()
142 if (!self
::$instance)
144 self
::$instance = new BSRegister();
145 set_error_handler(array(self
::$instance, '_errorHandler'));
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 trigger_error('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 trigger_error('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 trigger_error('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 trigger_error('Specifed module does not conform to the ISSO specification, or the class is missing');
409 // ###################################################################
411 * Prints an ISSO message
413 * @param string The title of the message
414 * @param string The content of the message
415 * @param integer Type of message to be printed
416 * @param bool Return the output?
417 * @param bool Show the debug stack?
418 * @param integer Message width
420 * @return mixed Output or null
422 public static function Message($title, $message, $type, $return = false, $stack = true, $width = 500)
447 echo "\n
<br
/>\n<table cellpadding
=\"4\" cellspacing
=\"1\" border
=\"0\" width
=\"$width\" style
=\"background
-color
: $color; color
: black
; font
-family
: Verdana
, sans
-serif
; font
-size
: 12px
;\">";
448 echo "\n
<tr style
=\"color
: $font; text
-align
: left\"
>\n\t<td
><strong
>$prefix: $title</strong
></td
>\n</tr
>";
449 echo "\n
<tr style
=\"background
-color
: #FFFFFF; text-align: left\">\n\t<td>$message</td>\n</tr>";
450 if ($stack AND self
::_Instance()->getDebug())
452 echo "\n<tr style=\"background-color: #FFFFFF; text-align: left\">\n\t<td><strong>Debug Stack:</strong> <pre>";
453 echo BSFunctions
::FormatBacktrace(debug_backtrace());
454 echo "</pre></td>\n</tr>";
456 echo "\n</table>\n<br />\n";
459 // ###################################################################
461 * Custom error handler for ISSO; only handle E_WARNING, E_NOTICE,
462 * E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE
464 * @param integer Error number
465 * @param string Error message string
466 * @param string File that contains the error
467 * @param string The line number of the error
468 * @param string The active symbol table at which point the error occurred
470 public function _errorHandler($errno, $errstr, $errfile, $errline, $errcontext)
472 $level = ini_get('error_reporting');
476 // So we don't need to specify the error type in trigger_error(), all E_USER_NOTICEs
477 // are fatal and automatically kill the script
483 // A non-fatal but important warning
487 if (!($level & E_WARNING
))
493 // A non-fatal notice that should all but be ignored unless in dev environments
498 if (!($level & E_NOTICE
))
507 trigger_error('The only error types supported are E_USER_NOTICE (fatal), E_WARNING, and E_NOTICE');
511 // change the file and line of the error so we aren't looking at the location of the trigger_error()
512 $backtrace = debug_backtrace();
513 if (isset($backtrace[1]) AND $backtrace[1]['function'] == 'trigger_error' AND isset($backtrace[2]['file']))
515 $errfile = $backtrace[2]['file'];
516 $errline = $backtrace[2]['line'];
519 $errstr .= " in <strong>$errfile</strong> on line <strong>$errline</strong>";
521 $errstr = str_replace(array(getcwd(), dirname(getcwd())), '', $errstr);
523 self
::Message($title, $errstr, $mode);
525 if ($errno == E_USER_NOTICE
)
531 // ###################################################################
533 * Creates a table that explains the error reporting levels and their
536 public static function ExplainErrorReporting()
539 'E_ERROR' => E_ERROR
,
540 'E_WARNING' => E_WARNING
,
541 'E_PARSE' => E_PARSE
,
542 'E_NOTICE' => E_NOTICE
,
543 'E_CORE_ERROR' => E_CORE_ERROR
,
544 'E_CORE_WARNING' => E_CORE_WARNING
,
545 'E_COMPILE_ERROR' => E_COMPILE_ERROR
,
546 'E_COMPILE_WARNING' => E_COMPILE_WARNING
,
547 'E_USER_ERROR' => E_USER_ERROR
,
548 'E_USER_WARNING' => E_USER_WARNING
,
549 'E_USER_NOTICE' => E_USER_NOTICE
,
551 'E_STRICT' => E_STRICT
554 $table = '<table cellspacing="0" cellpadding="2" border="0">';
556 foreach ($levels AS $name => $value)
560 <td>' . $name . '</td>
561 <td>' . (ini_get('error_reporting') & $value) . '</td>
568 self
::Message('Error Reporting', $table, 1);
571 // ###################################################################
573 * This function is used by other framework modules to check and see if
574 * the passed array of module names have been loaded. If not, this will
575 * throw an error informing the developer that the given modules are
576 * required in order for the framework to work.
578 * @param array Array of module names to check for loadedness
580 public static function RequiredModules($modules)
582 foreach ($modules AS $module)
584 if (self
::GetType($module) == null AND !class_exists("BS$module"))
586 trigger_error('The ' . $module . ' module is required in order to use this framework module');
592 /*=====================================================================*\
593 || ###################################################################
596 || ###################################################################
597 \*=====================================================================*/