]>
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 static 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 * Determines if there's a main register set. If not, returns FALSE.
160 * @return bool Is there a main register set?
162 public static function HasRegister()
164 return (isset(self
::SharedInstance()->main
) AND self
::SharedInstance()->main
instanceof BSRegister
);
167 // ###################################################################
169 * Loads the specified module.
171 * @param string Module name
173 * @return object Instantiated module
175 public static function LoadModule($name)
177 @include_once("ISSO/$name.php");
181 if (!class_exists($class))
183 trigger_error('Specifed module does not conform to the ISSO specification, or the class is missing');
190 // ###################################################################
192 * Prints an ISSO message
194 * @param string The title of the message
195 * @param string The content of the message
196 * @param integer Type of message to be printed
197 * @param bool Return the output?
198 * @param bool Show the debug stack?
199 * @param integer Message width
201 * @return mixed Output or null
203 public static function Message($title, $message, $type, $return = false, $stack = true, $width = 500)
228 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
;\">";
229 echo "\n
<tr style
=\"color
: $font; text
-align
: left\"
>\n\t<td
><strong
>$prefix: $title</strong
></td
>\n</tr
>";
230 echo "\n
<tr style
=\"background
-color
: #FFFFFF; text-align: left\">\n\t<td>$message</td>\n</tr>";
231 if ($stack AND self
::HasRegister() AND self
::GetRegister()->getDebug())
233 echo "\n<tr style=\"background-color: #FFFFFF; text-align: left\">\n\t<td><strong>Debug Stack:</strong> <pre>";
234 debug_print_backtrace();
235 echo "</pre></td>\n</tr>";
237 echo "\n</table>\n<br />\n";
240 // ###################################################################
242 * Custom error handler for ISSO; only handle E_WARNING, E_NOTICE,
243 * E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE
245 * @param integer Error number
246 * @param string Error message string
247 * @param string File that contains the error
248 * @param string The line number of the error
249 * @param string The active symbol table at which point the error occurred
251 private function _error_handler($errno, $errstr, $errfile, $errline, $errcontext)
253 $level = ini_get('error_reporting');
257 // So we don't need to specify the error type in trigger_error(), all E_USER_NOTICEs
258 // are fatal and automatically kill the script
264 // A non-fatal but important warning
268 if (!($level & E_WARNING
))
274 // A non-fatal notice that should all but be ignored unless in dev environments
279 if (!($level & E_NOTICE
))
288 trigger_error('The only error types supported are E_USER_NOTICE (fatal), E_WARNING, and E_NOTICE ' . $errno);
292 $errstr .= " in <strong>$errfile</strong> on line <strong>$errline</strong>";
294 $errstr = str_replace(array(getcwd(), dirname(getcwd())), '', $errstr);
296 self
::Message($title, $errstr, $mode);
298 if ($errno == E_USER_NOTICE
)
304 // ###################################################################
306 * Creates a table that explains the error reporting levels and their
309 public function explain_error_reporting()
312 'E_ERROR' => E_ERROR
,
313 'E_WARNING' => E_WARNING
,
314 'E_PARSE' => E_PARSE
,
315 'E_NOTICE' => E_NOTICE
,
316 'E_CORE_ERROR' => E_CORE_ERROR
,
317 'E_CORE_WARNING' => E_CORE_WARNING
,
318 'E_COMPILE_ERROR' => E_COMPILE_ERROR
,
319 'E_COMPILE_WARNING' => E_COMPILE_WARNING
,
320 'E_USER_ERROR' => E_USER_ERROR
,
321 'E_USER_WARNING' => E_USER_WARNING
,
322 'E_USER_NOTICE' => E_USER_NOTICE
,
324 'E_STRICT' => E_STRICT
327 $table = '<table cellspacing="0" cellpadding="2" border="0">';
329 foreach ($levels AS $name => $value)
333 <td>' . $name . '</td>
334 <td>' . (ini_get('error_reporting') & $value) . '</td>
341 $this->message('Error Reporting', $table, 1);
345 /*=====================================================================*\
346 || ###################################################################
349 || ###################################################################
350 \*=====================================================================*/