]>
src.bluestatic.org Git - isso.git/blob - Loader.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 * System loader (Loader.php)
31 * This class contains static methods that are used to create new registers and
35 * @copyright Copyright ©2002 - [#]year[#], Blue Static
46 private static $instance;
49 * Array of all the registers
52 private $registers = array();
60 // ###################################################################
64 private function __construct() {}
66 // ###################################################################
68 * Returns the shared instance of the BSLoader singleton class.
70 * @return object The BSLoader shared instance
72 private function SharedInstance()
76 self
::$instance = new BSLoader
;
77 set_error_handler(array(self
::$instance, '_error_handler'));
79 return self
::$instance;
82 // ###################################################################
84 * Creates a new BSRegister instance and returns it.
86 * @return object New register
88 public static function NewRegister()
90 require_once('ISSO/Register.php');
92 self
::SharedInstance()->registers
[] = new BSRegister();
94 return end(self
::SharedInstance()->registers
);
97 // ###################################################################
99 * Returns the array of all the registers
101 * @return array The array of all the registers
103 public static function GetAllRegisters()
105 return self
::SharedInstance()->registers
;
108 // ###################################################################
110 * Sets the main register
112 * @param object New main register
114 public static function SetRegister($register)
116 if (get_class($register) != 'BSRegister')
118 trigger_error('BSLoader::SetRegister() was not passed a BSRegister object');
122 self
::SharedInstance()->main
= $register;
125 // ###################################################################
127 * Gets the main register if no argument is passed, or an arbitrary
128 * one if the index of a register is passed.
130 * @param integer Register index
132 * @return object Specified register
134 public static function &GetRegister($index = null)
138 if (!isset(self
::SharedInstance()->main
))
140 trigger_error('Cannot fetch the main register because it has not been set with BSLoader::SetRegister()');
143 return self
::SharedInstance()->main
;
147 if (!isset(self
::SharedInstance()->registers
["$index"]))
149 trigger_error('Invalid register index passed to BSLoader::GetRegister()');
152 return self::SharedInstance()->registers["$index"];
156 // ###################################################################
158 * Loads the specified module.
160 * @param string Module name
162 * @return object Instantiated module
164 public static function LoadModule($name)
166 @include_once("ISSO/$name.php");
170 if (!class_exists($class))
172 trigger_error('Specifed module does not conform to the ISSO specification, or the class is missing');
179 // ###################################################################
181 * Prints an ISSO message
183 * @param string The title of the message
184 * @param string The content of the message
185 * @param integer Type of message to be printed
186 * @param bool Return the output?
187 * @param bool Show the debug stack?
188 * @param integer Message width
190 * @return mixed Output or null
192 public static function Message($title, $message, $type, $return = false, $stack = true, $width = 500)
217 $backtrace = debug_backtrace();
218 array_shift($backtrace);
220 if (isset($backtrace[0]) AND $backtrace[0]['function'] == '_error_handler')
222 array_shift($backtrace);
225 $trace = BSFunctions::FormatDebugTrace($backtrace);
227 $output = "\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
;\">";
228 $output .= "\n
<tr style
=\"color
: $font; text
-align
: left\"
>\n\t<td
><strong
>$prefix: $title</strong
></td
>\n</tr
>";
229 $output .= "\n
<tr style
=\"background
-color
: #FFFFFF; text-align: left\">\n\t<td>$message</td>\n</tr>";
230 $output .= (($stack AND self
::GetRegister()->getDebug()) ? "\n<tr style=\"background-color: #FFFFFF; text-align: left\">\n\t<td><strong>Debug Stack:</strong> <pre>" . implode("\n", $trace) . "</pre></td>\n</tr>" : '');
231 $output .= "\n</table>\n<br />\n";
243 // ###################################################################
245 * Custom error handler for ISSO; only handle E_WARNING, E_NOTICE,
246 * E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE
248 * @param integer Error number
249 * @param string Error message string
250 * @param string File that contains the error
251 * @param string The line number of the error
252 * @param string The active symbol table at which point the error occurred
254 private function _error_handler($errno, $errstr, $errfile, $errline, $errcontext)
256 $level = ini_get('error_reporting');
260 // So we don't need to specify the error type in trigger_error(), all E_USER_NOTICEs
261 // are fatal and automatically kill the script
267 // A non-fatal but important warning
271 if (!($level & E_WARNING
))
277 // A non-fatal notice that should all but be ignored unless in dev environments
282 if (!($level & E_NOTICE
))
291 trigger_error('The only error types supported are E_USER_NOTICE (fatal), E_WARNING, and E_NOTICE ' . $errno);
295 $errstr .= " in <strong>$errfile</strong> on line <strong>$errline</strong>";
297 $errstr = str_replace(array(getcwd(), dirname(getcwd())), '', $errstr);
299 self
::Message($title, $errstr, $mode);
301 if ($errno == E_USER_NOTICE
)
307 // ###################################################################
309 * Creates a table that explains the error reporting levels and their
312 public function explain_error_reporting()
315 'E_ERROR' => E_ERROR
,
316 'E_WARNING' => E_WARNING
,
317 'E_PARSE' => E_PARSE
,
318 'E_NOTICE' => E_NOTICE
,
319 'E_CORE_ERROR' => E_CORE_ERROR
,
320 'E_CORE_WARNING' => E_CORE_WARNING
,
321 'E_COMPILE_ERROR' => E_COMPILE_ERROR
,
322 'E_COMPILE_WARNING' => E_COMPILE_WARNING
,
323 'E_USER_ERROR' => E_USER_ERROR
,
324 'E_USER_WARNING' => E_USER_WARNING
,
325 'E_USER_NOTICE' => E_USER_NOTICE
,
327 'E_STRICT' => E_STRICT
330 $table = '<table cellspacing="0" cellpadding="2" border="0">';
332 foreach ($levels AS $name => $value)
336 <td>' . $name . '</td>
337 <td>' . (ini_get('error_reporting') & $value) . '</td>
344 $this->message('Error Reporting', $table, 1);
348 /*=====================================================================*\
349 || ###################################################################
352 || ###################################################################
353 \*=====================================================================*/