]>
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)
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)
57 * This class contains static methods that are used to create new registers and
61 * @copyright Copyright ©2002 - [#]year[#], Blue Static
72 private static $instance;
75 * Array of all the registers
78 private $registers = array();
86 // ###################################################################
90 private function __construct() {}
92 // ###################################################################
94 * Returns the shared instance of the BSLoader singleton class.
96 * @return object The BSLoader shared instance
98 private static function SharedInstance()
100 if (!self
::$instance)
102 self
::$instance = new BSLoader
;
103 set_error_handler(array(self
::$instance, 'errorHandler'));
105 return self
::$instance;
108 // ###################################################################
110 * Creates a new BSRegister instance and returns it.
112 * @return object New register
114 public static function NewRegister()
116 require_once('ISSO/Register.php');
118 self
::SharedInstance()->registers
[] = $return = new BSRegister();
123 // ###################################################################
125 * Returns the array of all the registers
127 * @return array The array of all the registers
129 public static function GetAllRegisters()
131 return self
::SharedInstance()->registers
;
134 // ###################################################################
136 * Sets the main register
138 * @param object New main register
140 public static function SetRegister($register)
142 if (get_class($register) != 'BSRegister')
144 trigger_error('BSLoader::SetRegister() was not passed a BSRegister object');
148 self
::SharedInstance()->main
= $register;
151 // ###################################################################
153 * Gets the main register if no argument is passed, or an arbitrary
154 * one if the index of a register is passed.
156 * @param integer Register index
158 * @return object Specified register
160 public static function &GetRegister($index = null)
164 if (!isset(self
::SharedInstance()->main
))
166 trigger_error('Cannot fetch the main register because it has not been set with BSLoader::SetRegister()');
169 return self
::SharedInstance()->main
;
173 if (!isset(self
::SharedInstance()->registers
["$index"]))
175 trigger_error('Invalid register index passed to BSLoader::GetRegister()');
178 return self::SharedInstance()->registers["$index"];
182 // ###################################################################
184 * Determines if there's a main register set. If not, returns FALSE.
186 * @return bool Is there a main register set?
188 public static function HasRegister()
190 return (isset(self
::SharedInstance()->main
) AND self
::SharedInstance()->main
instanceof BSRegister
);
193 // ###################################################################
195 * Loads the specified module.
197 * @param string Module name
199 * @return object Instantiated module
201 public static function LoadModule($name)
203 @include_once("ISSO/$name.php");
207 if (!class_exists($class))
209 trigger_error('Specifed module does not conform to the ISSO specification, or the class is missing');
216 // ###################################################################
218 * Prints an ISSO message
220 * @param string The title of the message
221 * @param string The content of the message
222 * @param integer Type of message to be printed
223 * @param bool Return the output?
224 * @param bool Show the debug stack?
225 * @param integer Message width
227 * @return mixed Output or null
229 public static function Message($title, $message, $type, $return = false, $stack = true, $width = 500)
254 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
;\">";
255 echo "\n
<tr style
=\"color
: $font; text
-align
: left\"
>\n\t<td
><strong
>$prefix: $title</strong
></td
>\n</tr
>";
256 echo "\n
<tr style
=\"background
-color
: #FFFFFF; text-align: left\">\n\t<td>$message</td>\n</tr>";
257 if ($stack AND self
::HasRegister() AND self
::GetRegister()->getDebug())
259 echo "\n<tr style=\"background-color: #FFFFFF; text-align: left\">\n\t<td><strong>Debug Stack:</strong> <pre>";
260 debug_print_backtrace();
261 echo "</pre></td>\n</tr>";
263 echo "\n</table>\n<br />\n";
266 // ###################################################################
268 * Custom error handler for ISSO; only handle E_WARNING, E_NOTICE,
269 * E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE
271 * @param integer Error number
272 * @param string Error message string
273 * @param string File that contains the error
274 * @param string The line number of the error
275 * @param string The active symbol table at which point the error occurred
277 private function errorHandler($errno, $errstr, $errfile, $errline, $errcontext)
279 $level = ini_get('error_reporting');
283 // So we don't need to specify the error type in trigger_error(), all E_USER_NOTICEs
284 // are fatal and automatically kill the script
290 // A non-fatal but important warning
294 if (!($level & E_WARNING
))
300 // A non-fatal notice that should all but be ignored unless in dev environments
305 if (!($level & E_NOTICE
))
314 trigger_error('The only error types supported are E_USER_NOTICE (fatal), E_WARNING, and E_NOTICE');
318 $errstr .= " in <strong>$errfile</strong> on line <strong>$errline</strong>";
320 $errstr = str_replace(array(getcwd(), dirname(getcwd())), '', $errstr);
322 self
::Message($title, $errstr, $mode);
324 if ($errno == E_USER_NOTICE
)
330 // ###################################################################
332 * Creates a table that explains the error reporting levels and their
335 public static function ExplainErrorReporting()
338 'E_ERROR' => E_ERROR
,
339 'E_WARNING' => E_WARNING
,
340 'E_PARSE' => E_PARSE
,
341 'E_NOTICE' => E_NOTICE
,
342 'E_CORE_ERROR' => E_CORE_ERROR
,
343 'E_CORE_WARNING' => E_CORE_WARNING
,
344 'E_COMPILE_ERROR' => E_COMPILE_ERROR
,
345 'E_COMPILE_WARNING' => E_COMPILE_WARNING
,
346 'E_USER_ERROR' => E_USER_ERROR
,
347 'E_USER_WARNING' => E_USER_WARNING
,
348 'E_USER_NOTICE' => E_USER_NOTICE
,
350 'E_STRICT' => E_STRICT
353 $table = '<table cellspacing="0" cellpadding="2" border="0">';
355 foreach ($levels AS $name => $value)
359 <td>' . $name . '</td>
360 <td>' . (ini_get('error_reporting') & $value) . '</td>
367 self
::Message('Error Reporting', $table, 1);
371 /*=====================================================================*\
372 || ###################################################################
375 || ###################################################################
376 \*=====================================================================*/