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 public 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 function setApplication($name)
152 $this->application
= $name;
155 // ###################################################################
157 * Gets the application name
159 * @return string Application name
161 public function getApplication()
163 return $this->application
;
166 // ###################################################################
168 * Sets the application's working path
172 public function setAppPath($path)
174 $this->appPath
= BSFunctions
::FetchSourcePath($path);
177 // ###################################################################
179 * Returns the path to the application
181 * @return string Application path
183 public function getAppPath()
185 return $this->appPath
;
188 // ###################################################################
190 * Sets the application version
192 * @param string Application version
194 public function setAppVersion($vers)
196 $this->appVersion
= $vers;
199 // ###################################################################
201 * Gets the application version
203 * @return string Application version
205 public function getAppVersion()
207 return $this->appVersion
;
210 // ###################################################################
212 * Sets the application's web path, which is the full path from the
217 public function setWebPath($path)
219 $this->webPath
= BSFunctions
::FetchSourcePath($path);
222 // ###################################################################
224 * Returns the web path to the application
226 * @return string Application's web path
228 public function getWebPath()
230 return $this->webPath
;
233 // ###################################################################
235 * Sets the debug state
237 * @param bool Debug mode on?
239 public function setDebug($debug)
241 $this->debug
= $debug;
244 // ###################################################################
246 * Gets the debug mode state
248 * @return bool Debug mode on?
250 public function getDebug()
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 function register($key, $value)
265 if (isset($this->registry
["$key"]))
267 trigger_error('Cannot overwrite a key in the registry');
271 $this->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 function unregister($key)
283 if (!isset($this->registry
["$key"]))
285 trigger_error('You cannot unregister a key that does not exist');
289 unset($this->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 function get($key)
302 if (!isset($this->registry
["$key"]))
304 trigger_error('Cannot access the registry with a non-existent key');
308 return $this->registry
["$key"];
311 // ###################################################################
313 * Returns the entire registry stack
315 * @return array Complete registry
317 public function getAll()
319 return $this->registry
;
322 // ###################################################################
324 * Adds a debug message to the array. This only works when debug mode
327 * @param string Debug message
329 public function debug($msg)
333 $this->debugInfo
[] = $msg;
337 // ###################################################################
339 * Loads the specified module.
341 * @param string Module name
343 * @return object Instantiated module
345 public static function LoadModule($name)
347 @include_once("ISSO/$name.php");
351 if (!class_exists($class))
353 trigger_error('Specifed module does not conform to the ISSO specification, or the class is missing');
360 // ###################################################################
362 * Prints an ISSO message
364 * @param string The title of the message
365 * @param string The content of the message
366 * @param integer Type of message to be printed
367 * @param bool Return the output?
368 * @param bool Show the debug stack?
369 * @param integer Message width
371 * @return mixed Output or null
373 public static function Message($title, $message, $type, $return = false
, $stack = true
, $width = 500)
398 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;\">";
399 echo "\n<tr style=\"color: $font; text-align: left\">\n\t<td><strong>$prefix: $title</strong></td>\n</tr>";
400 echo "\n<tr style=\"background-color: #FFFFFF; text-align: left\">\n\t<td>$message</td>\n</tr>";
401 if ($stack AND self
::Instance()->getDebug())
403 echo "\n<tr style=\"background-color: #FFFFFF; text-align: left\">\n\t<td><strong>Debug Stack:</strong> <pre>";
404 debug_print_backtrace();
405 echo "</pre></td>\n</tr>";
407 echo "\n</table>\n<br />\n";
410 // ###################################################################
412 * Custom error handler for ISSO; only handle E_WARNING, E_NOTICE,
413 * E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE
415 * @param integer Error number
416 * @param string Error message string
417 * @param string File that contains the error
418 * @param string The line number of the error
419 * @param string The active symbol table at which point the error occurred
421 private function _errorHandler($errno, $errstr, $errfile, $errline, $errcontext)
423 $level = ini_get('error_reporting');
427 // So we don't need to specify the error type in trigger_error(), all E_USER_NOTICEs
428 // are fatal and automatically kill the script
434 // A non-fatal but important warning
438 if (!($level & E_WARNING
))
444 // A non-fatal notice that should all but be ignored unless in dev environments
449 if (!($level & E_NOTICE
))
458 trigger_error('The only error types supported are E_USER_NOTICE (fatal), E_WARNING, and E_NOTICE');
462 $errstr .= " in <strong>$errfile</strong> on line <strong>$errline</strong>";
464 $errstr = str_replace(array(getcwd(), dirname(getcwd())), '', $errstr);
466 self
::Message($title, $errstr, $mode);
468 if ($errno == E_USER_NOTICE
)
474 // ###################################################################
476 * Creates a table that explains the error reporting levels and their
479 public static function ExplainErrorReporting()
482 'E_ERROR' => E_ERROR
,
483 'E_WARNING' => E_WARNING
,
484 'E_PARSE' => E_PARSE
,
485 'E_NOTICE' => E_NOTICE
,
486 'E_CORE_ERROR' => E_CORE_ERROR
,
487 'E_CORE_WARNING' => E_CORE_WARNING
,
488 'E_COMPILE_ERROR' => E_COMPILE_ERROR
,
489 'E_COMPILE_WARNING' => E_COMPILE_WARNING
,
490 'E_USER_ERROR' => E_USER_ERROR
,
491 'E_USER_WARNING' => E_USER_WARNING
,
492 'E_USER_NOTICE' => E_USER_NOTICE
,
494 'E_STRICT' => E_STRICT
497 $table = '<table cellspacing="0" cellpadding="2" border="0">';
499 foreach ($levels AS $name => $value)
503 <td>' . $name . '</td>
504 <td>' . (ini_get('error_reporting') & $value) . '</td>
511 self
::Message('Error Reporting', $table, 1);
515 /*=====================================================================*\
516 || ###################################################################
519 || ###################################################################
520 \*=====================================================================*/