]>
src.bluestatic.org Git - isso.git/blob - Register.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework [#]issoversion[#]
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)
28 // we need PHP5 to run
29 if (!function_exists('stripos'))
31 trigger_error('You need PHP version 5.0.0 or newer to run ISSO', E_USER_ERROR
);
35 // get rid of register_globals
36 if ((bool)ini_get('register_globals') === true)
38 $superglobals = array('_GET', '_COOKIE', '_FILES', '_POST', '_SERVER', '_ENV');
39 foreach ($superglobals AS $global)
41 if (is_array(${$global}))
43 foreach (${$global} AS $_key => $_val)
54 require_once('ISSO/Functions.php');
59 * This is an ISSO registry class. It holds all of the ISSO system variables as well
60 * as serving as an object registry that is avaliable in the global scope to prevent
61 * globalization of variables. There can only be one instance of this existing
65 * @copyright Copyright ©2002 - [#]year[#], Blue Static
73 * Instance of this class
76 private static $instance;
82 private $application = 'Unknown ISSO Project';
106 private $debug = false;
109 * The master registry list
112 private $registry = array();
115 * An array of debug messages
118 private $debugInfo = array();
120 // ###################################################################
124 private function __construct() {}
126 // ###################################################################
128 * Returns the single instance of the register
130 * @param string A string param
132 * @return object BSRegister instance
134 private static function Instance()
136 if (self
::$instance == null)
138 self
::$instance = new BSRegister();
139 set_error_handler(array(self
::$instance, '_errorHandler'));
141 return self
::$instance;
144 // ###################################################################
146 * Sets the application name
148 * @param string Application name
150 public static function SetApplication($name)
152 self
::Instance()->application
= $name;
155 // ###################################################################
157 * Gets the application name
159 * @return string Application name
161 public static function GetApplication()
163 return self
::Instance()->application
;
166 // ###################################################################
168 * Sets the application's working path
172 public static function SetAppPath($path)
174 self
::Instance()->appPath
= BSFunctions
::FetchSourcePath($path);
177 // ###################################################################
179 * Returns the path to the application
181 * @return string Application path
183 public static function GetAppPath()
185 return self
::Instance()->appPath
;
188 // ###################################################################
190 * Sets the application version
192 * @param string Application version
194 public static function SetAppVersion($vers)
196 self
::Instance()->appVersion
= $vers;
199 // ###################################################################
201 * Gets the application version
203 * @return string Application version
205 public static function GetAppVersion()
207 return self
::Instance()->appVersion
;
210 // ###################################################################
212 * Sets the application's web path, which is the full path from the
217 public static function SetWebPath($path)
219 self
::Instance()->webPath
= BSFunctions
::FetchSourcePath($path);
222 // ###################################################################
224 * Returns the web path to the application
226 * @return string Application's web path
228 public static function GetWebPath()
230 return self
::Instance()->webPath
;
233 // ###################################################################
235 * Sets the debug state
237 * @param bool Debug mode on?
239 public static function SetDebug($debug)
241 self
::Instance()->debug
= $debug;
244 // ###################################################################
246 * Gets the debug mode state
248 * @return bool Debug mode on?
250 public static function GetDebug()
252 return self
::Instance()->debug
;
255 // ###################################################################
257 * Registers a value in the master registry. You cannot overwrite
258 * values. You must first unregister() them if you wish to do so.
260 * @param string Registry key
261 * @param mixed Value to register
263 public static function Register($key, $value)
265 if (isset(self
::Instance()->registry
["$key"]))
267 trigger_error('Cannot overwrite a key in the registry');
271 self::Instance()->registry["$key"] = $value;
274 // ###################################################################
276 * Unregisters a value from the registry. This removes all traces of
277 * it from this object.
279 * @param string Registry key
281 public static function Unregister($key)
283 if (!isset(self
::Instance()->registry
["$key"]))
285 trigger_error('You cannot unregister a key that does not exist');
289 unset(self::Instance()->registry["$key"]);
292 // ###################################################################
294 * This gets a value from the registry with a specific key
296 * @param string The key
298 * @return mixed Value in the registry for key
300 public static function Get($key)
302 if (!isset(self
::Instance()->registry
["$key"]))
304 trigger_error('Cannot access the registry with a non-existent key');
308 return self::Instance()->registry["$key"];
311 // ###################################################################
313 * Returns the first object of a specified class type
315 * @param string Class name
317 * @return object Object in the registry of that type
319 public static function GetType($class)
321 $class = 'BS' . $class;
322 foreach (self
::Instance()->registry
AS $key => $object)
324 if ($object instanceof $class)
331 // ###################################################################
333 * Returns the entire registry stack
335 * @return array Complete registry
337 public static function GetAll()
339 return self
::Instance()->registry
;
342 // ###################################################################
344 * Adds a debug message to the array. This only works when debug mode
347 * @param string Debug message
349 public static function Debug($msg)
351 if (self
::Instance()->debug
)
353 self
::Instance()->debugInfo
[] = $msg;
357 // ###################################################################
359 * Loads the specified module.
361 * @param string Module name
363 * @return object Instantiated module
365 public static function LoadModule($name)
367 if (BSRegister
::GetDebug())
369 include_once("ISSO/$name.php");
373 @include_once("ISSO/$name.php");
378 if (!class_exists($class))
380 trigger_error('Specifed module does not conform to the ISSO specification, or the class is missing');
387 // ###################################################################
389 * Prints an ISSO message
391 * @param string The title of the message
392 * @param string The content of the message
393 * @param integer Type of message to be printed
394 * @param bool Return the output?
395 * @param bool Show the debug stack?
396 * @param integer Message width
398 * @return mixed Output or null
400 public static function Message($title, $message, $type, $return = false, $stack = true, $width = 500)
425 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
;\">";
426 echo "\n
<tr style
=\"color
: $font; text
-align
: left\"
>\n\t<td
><strong
>$prefix: $title</strong
></td
>\n</tr
>";
427 echo "\n
<tr style
=\"background
-color
: #FFFFFF; text-align: left\">\n\t<td>$message</td>\n</tr>";
428 if ($stack AND self
::Instance()->getDebug())
430 echo "\n<tr style=\"background-color: #FFFFFF; text-align: left\">\n\t<td><strong>Debug Stack:</strong> <pre>";
431 debug_print_backtrace();
432 echo "</pre></td>\n</tr>";
434 echo "\n</table>\n<br />\n";
437 // ###################################################################
439 * Custom error handler for ISSO; only handle E_WARNING, E_NOTICE,
440 * E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE
442 * @param integer Error number
443 * @param string Error message string
444 * @param string File that contains the error
445 * @param string The line number of the error
446 * @param string The active symbol table at which point the error occurred
448 public function _errorHandler($errno, $errstr, $errfile, $errline, $errcontext)
450 $level = ini_get('error_reporting');
454 // So we don't need to specify the error type in trigger_error(), all E_USER_NOTICEs
455 // are fatal and automatically kill the script
461 // A non-fatal but important warning
465 if (!($level & E_WARNING
))
471 // A non-fatal notice that should all but be ignored unless in dev environments
476 if (!($level & E_NOTICE
))
485 trigger_error('The only error types supported are E_USER_NOTICE (fatal), E_WARNING, and E_NOTICE');
489 $errstr .= " in <strong>$errfile</strong> on line <strong>$errline</strong>";
491 $errstr = str_replace(array(getcwd(), dirname(getcwd())), '', $errstr);
493 self
::Message($title, $errstr, $mode);
495 if ($errno == E_USER_NOTICE
)
501 // ###################################################################
503 * Creates a table that explains the error reporting levels and their
506 public static function ExplainErrorReporting()
509 'E_ERROR' => E_ERROR
,
510 'E_WARNING' => E_WARNING
,
511 'E_PARSE' => E_PARSE
,
512 'E_NOTICE' => E_NOTICE
,
513 'E_CORE_ERROR' => E_CORE_ERROR
,
514 'E_CORE_WARNING' => E_CORE_WARNING
,
515 'E_COMPILE_ERROR' => E_COMPILE_ERROR
,
516 'E_COMPILE_WARNING' => E_COMPILE_WARNING
,
517 'E_USER_ERROR' => E_USER_ERROR
,
518 'E_USER_WARNING' => E_USER_WARNING
,
519 'E_USER_NOTICE' => E_USER_NOTICE
,
521 'E_STRICT' => E_STRICT
524 $table = '<table cellspacing="0" cellpadding="2" border="0">';
526 foreach ($levels AS $name => $value)
530 <td>' . $name . '</td>
531 <td>' . (ini_get('error_reporting') & $value) . '</td>
538 self
::Message('Error Reporting', $table, 1);
541 // ###################################################################
543 * This function is used by other framework modules to check and see if
544 * the passed array of module names have been loaded. If not, this will
545 * throw an error informing the developer that the given modules are
546 * required in order for the framework to work.
548 * @param array Array of module names to check for loadedness
550 public static function RequiredModules($modules)
552 foreach ($modules AS $module)
554 if (self
::GetType($module) == null)
556 trigger_error('The ' . $module . ' is required in order to use this framework module');
562 /*=====================================================================*\
563 || ###################################################################
566 || ###################################################################
567 \*=====================================================================*/