]>
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()
67 // ###################################################################
69 * Returns the shared instance of the BSLoader singleton class.
71 * @return object The BSLoader shared instance
73 private static function SharedInstance()
77 self
::$instance = new BSLoader
;
78 set_error_handler(array(self
::$instance, '_error_handler'));
80 return self
::$instance;
83 // ###################################################################
85 * Creates a new BSRegister instance and returns it.
87 * @return object New register
89 public static function NewRegister()
91 require_once('ISSO/Register.php');
93 self
::SharedInstance()->registers
[] = $return = new BSRegister();
98 // ###################################################################
100 * Returns the array of all the registers
102 * @return array The array of all the registers
104 public static function GetAllRegisters()
106 return self
::SharedInstance()->registers
;
109 // ###################################################################
111 * Sets the main register
113 * @param object New main register
115 public static function SetRegister($register)
117 if (get_class($register) != 'BSRegister')
119 trigger_error('BSLoader::SetRegister() was not passed a BSRegister object');
123 self
::SharedInstance()->main
= $register;
126 // ###################################################################
128 * Gets the main register if no argument is passed, or an arbitrary
129 * one if the index of a register is passed.
131 * @param integer Register index
133 * @return object Specified register
135 public static function &GetRegister($index = null)
139 if (!isset(self
::SharedInstance()->main
))
141 trigger_error('Cannot fetch the main register because it has not been set with BSLoader::SetRegister()');
144 return self
::SharedInstance()->main
;
148 if (!isset(self
::SharedInstance()->registers
["$index"]))
150 trigger_error('Invalid register index passed to BSLoader::GetRegister()');
153 return self::SharedInstance()->registers["$index"];
157 // ###################################################################
159 * Determines if there's a main register set. If not, returns FALSE.
161 * @return bool Is there a main register set?
163 public static function HasRegister()
165 return (isset(self
::SharedInstance()->main
) AND self
::SharedInstance()->main
instanceof BSRegister
);
168 // ###################################################################
170 * Loads the specified module.
172 * @param string Module name
174 * @return object Instantiated module
176 public static function LoadModule($name)
178 @include_once("ISSO/$name.php");
182 if (!class_exists($class))
184 trigger_error('Specifed module does not conform to the ISSO specification, or the class is missing');
191 // ###################################################################
193 * Prints an ISSO message
195 * @param string The title of the message
196 * @param string The content of the message
197 * @param integer Type of message to be printed
198 * @param bool Return the output?
199 * @param bool Show the debug stack?
200 * @param integer Message width
202 * @return mixed Output or null
204 public static function Message($title, $message, $type, $return = false, $stack = true, $width = 500)
229 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
;\">";
230 echo "\n
<tr style
=\"color
: $font; text
-align
: left\"
>\n\t<td
><strong
>$prefix: $title</strong
></td
>\n</tr
>";
231 echo "\n
<tr style
=\"background
-color
: #FFFFFF; text-align: left\">\n\t<td>$message</td>\n</tr>";
232 if ($stack AND self
::HasRegister() AND self
::GetRegister()->getDebug())
234 echo "\n<tr style=\"background-color: #FFFFFF; text-align: left\">\n\t<td><strong>Debug Stack:</strong> <pre>";
235 debug_print_backtrace();
236 echo "</pre></td>\n</tr>";
238 echo "\n</table>\n<br />\n";
241 // ###################################################################
243 * Custom error handler for ISSO; only handle E_WARNING, E_NOTICE,
244 * E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE
246 * @param integer Error number
247 * @param string Error message string
248 * @param string File that contains the error
249 * @param string The line number of the error
250 * @param string The active symbol table at which point the error occurred
252 private function _error_handler($errno, $errstr, $errfile, $errline, $errcontext)
254 $level = ini_get('error_reporting');
258 // So we don't need to specify the error type in trigger_error(), all E_USER_NOTICEs
259 // are fatal and automatically kill the script
265 // A non-fatal but important warning
269 if (!($level & E_WARNING
))
275 // A non-fatal notice that should all but be ignored unless in dev environments
280 if (!($level & E_NOTICE
))
289 trigger_error('The only error types supported are E_USER_NOTICE (fatal), E_WARNING, and E_NOTICE');
293 $errstr .= " in <strong>$errfile</strong> on line <strong>$errline</strong>";
295 $errstr = str_replace(array(getcwd(), dirname(getcwd())), '', $errstr);
297 self
::Message($title, $errstr, $mode);
299 if ($errno == E_USER_NOTICE
)
305 // ###################################################################
307 * Creates a table that explains the error reporting levels and their
310 public static function ExplainErrorReporting()
313 'E_ERROR' => E_ERROR
,
314 'E_WARNING' => E_WARNING
,
315 'E_PARSE' => E_PARSE
,
316 'E_NOTICE' => E_NOTICE
,
317 'E_CORE_ERROR' => E_CORE_ERROR
,
318 'E_CORE_WARNING' => E_CORE_WARNING
,
319 'E_COMPILE_ERROR' => E_COMPILE_ERROR
,
320 'E_COMPILE_WARNING' => E_COMPILE_WARNING
,
321 'E_USER_ERROR' => E_USER_ERROR
,
322 'E_USER_WARNING' => E_USER_WARNING
,
323 'E_USER_NOTICE' => E_USER_NOTICE
,
325 'E_STRICT' => E_STRICT
328 $table = '<table cellspacing="0" cellpadding="2" border="0">';
330 foreach ($levels AS $name => $value)
334 <td>' . $name . '</td>
335 <td>' . (ini_get('error_reporting') & $value) . '</td>
342 self
::Message('Error Reporting', $table, 1);
346 /*=====================================================================*\
347 || ###################################################################
350 || ###################################################################
351 \*=====================================================================*/