]>
src.bluestatic.org Git - isso.git/blob - Register.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 * 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 // ###################################################################
122 * Constructor: set the error handler
124 private function __construct()
126 set_error_handler(array(self
::$instance, '_errorHandler'));
129 // ###################################################################
131 * Returns the single instance of the register
133 * @param string A string param
135 * @return object BSRegister instance
137 public static function Instance()
139 if (self
::$instance == null)
141 self
::$instance = new BSRegister();
143 return self
::$instance;
146 // ###################################################################
148 * Sets the application name
150 * @param string Application name
152 public function setApplication($name)
154 $this->application
= $name;
157 // ###################################################################
159 * Gets the application name
161 * @return string Application name
163 public function getApplication()
165 return $this->application
;
168 // ###################################################################
170 * Sets the application's working path
174 public function setAppPath($path)
176 $this->appPath
= BSFunctions
::FetchSourcePath($path);
179 // ###################################################################
181 * Returns the path to the application
183 * @return string Application path
185 public function getAppPath()
187 return $this->appPath
;
190 // ###################################################################
192 * Sets the application version
194 * @param string Application version
196 public function setAppVersion($vers)
198 $this->appVersion
= $vers;
201 // ###################################################################
203 * Gets the application version
205 * @return string Application version
207 public function getAppVersion()
209 return $this->appVersion
;
212 // ###################################################################
214 * Sets the application's web path, which is the full path from the
219 public function setWebPath($path)
221 $this->webPath
= BSFunctions
::FetchSourcePath($path);
224 // ###################################################################
226 * Returns the web path to the application
228 * @return string Application's web path
230 public function getWebPath()
232 return $this->webPath
;
235 // ###################################################################
237 * Sets the debug state
239 * @param bool Debug mode on?
241 public function setDebug($debug)
243 $this->debug
= $debug;
246 // ###################################################################
248 * Gets the debug mode state
250 * @return bool Debug mode on?
252 public function getDebug()
257 // ###################################################################
259 * Registers a value in the master registry. You cannot overwrite
260 * values. You must first unregister() them if you wish to do so.
262 * @param string Registry key
263 * @param mixed Value to register
265 public function register($key, $value)
267 if (isset($this->registry
["$key"]))
269 trigger_error('Cannot overwrite a key in the registry');
273 $this->registry["$key"] = $value;
276 // ###################################################################
278 * Unregisters a value from the registry. This removes all traces of
279 * it from this object.
281 * @param string Registry key
283 public function unregister($key)
285 if (!isset($this->registry
["$key"]))
287 trigger_error('You cannot unregister a key that does not exist');
291 unset($this->registry["$key"]);
294 // ###################################################################
296 * This gets a value from the registry with a specific key
298 * @param string The key
300 * @return mixed Value in the registry for key
302 public function get($key)
304 if (!isset($this->registry
["$key"]))
306 trigger_error('Cannot access the registry with a non-existent key');
310 return $this->registry["$key"];
313 // ###################################################################
315 * Returns the entire registry stack
317 * @return array Complete registry
319 public function getAll()
321 return $this->registry
;
324 // ###################################################################
326 * Adds a debug message to the array. This only works when debug mode
329 * @param string Debug message
331 public function debug($msg)
335 $this->debugInfo
[] = $msg;
339 // ###################################################################
341 * Loads the specified module.
343 * @param string Module name
345 * @return object Instantiated module
347 public static function LoadModule($name)
349 @include_once("ISSO/$name.php");
353 if (!class_exists($class))
355 trigger_error('Specifed module does not conform to the ISSO specification, or the class is missing');
362 // ###################################################################
364 * Prints an ISSO message
366 * @param string The title of the message
367 * @param string The content of the message
368 * @param integer Type of message to be printed
369 * @param bool Return the output?
370 * @param bool Show the debug stack?
371 * @param integer Message width
373 * @return mixed Output or null
375 public static function Message($title, $message, $type, $return = false, $stack = true, $width = 500)
400 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
;\">";
401 echo "\n
<tr style
=\"color
: $font; text
-align
: left\"
>\n\t<td
><strong
>$prefix: $title</strong
></td
>\n</tr
>";
402 echo "\n
<tr style
=\"background
-color
: #FFFFFF; text-align: left\">\n\t<td>$message</td>\n</tr>";
403 if ($stack AND self
::Instance()->getDebug())
405 echo "\n<tr style=\"background-color: #FFFFFF; text-align: left\">\n\t<td><strong>Debug Stack:</strong> <pre>";
406 debug_print_backtrace();
407 echo "</pre></td>\n</tr>";
409 echo "\n</table>\n<br />\n";
412 // ###################################################################
414 * Custom error handler for ISSO; only handle E_WARNING, E_NOTICE,
415 * E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE
417 * @param integer Error number
418 * @param string Error message string
419 * @param string File that contains the error
420 * @param string The line number of the error
421 * @param string The active symbol table at which point the error occurred
423 private function _errorHandler($errno, $errstr, $errfile, $errline, $errcontext)
425 $level = ini_get('error_reporting');
429 // So we don't need to specify the error type in trigger_error(), all E_USER_NOTICEs
430 // are fatal and automatically kill the script
436 // A non-fatal but important warning
440 if (!($level & E_WARNING
))
446 // A non-fatal notice that should all but be ignored unless in dev environments
451 if (!($level & E_NOTICE
))
460 trigger_error('The only error types supported are E_USER_NOTICE (fatal), E_WARNING, and E_NOTICE');
464 $errstr .= " in <strong>$errfile</strong> on line <strong>$errline</strong>";
466 $errstr = str_replace(array(getcwd(), dirname(getcwd())), '', $errstr);
468 self
::Message($title, $errstr, $mode);
470 if ($errno == E_USER_NOTICE
)
476 // ###################################################################
478 * Creates a table that explains the error reporting levels and their
481 public static function ExplainErrorReporting()
484 'E_ERROR' => E_ERROR
,
485 'E_WARNING' => E_WARNING
,
486 'E_PARSE' => E_PARSE
,
487 'E_NOTICE' => E_NOTICE
,
488 'E_CORE_ERROR' => E_CORE_ERROR
,
489 'E_CORE_WARNING' => E_CORE_WARNING
,
490 'E_COMPILE_ERROR' => E_COMPILE_ERROR
,
491 'E_COMPILE_WARNING' => E_COMPILE_WARNING
,
492 'E_USER_ERROR' => E_USER_ERROR
,
493 'E_USER_WARNING' => E_USER_WARNING
,
494 'E_USER_NOTICE' => E_USER_NOTICE
,
496 'E_STRICT' => E_STRICT
499 $table = '<table cellspacing="0" cellpadding="2" border="0">';
501 foreach ($levels AS $name => $value)
505 <td>' . $name . '</td>
506 <td>' . (ini_get('error_reporting') & $value) . '</td>
513 self
::Message('Error Reporting', $table, 1);
517 /*=====================================================================*\
518 || ###################################################################
521 || ###################################################################
522 \*=====================================================================*/