]> git.mxchange.org Git - hub.git/blobdiff - application/hub/exceptions.php
A lot files renamed (sorry guys for the mess) and moved to sub directories
[hub.git] / application / hub / exceptions.php
index 7b569dc187fba0d3f804d19f5b6710db7276b019..05a27767b08b14c9c21f41df4cdf9b8782754790 100644 (file)
@@ -5,7 +5,7 @@
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0
- * @copyright  Copyright(c) 2007, 2008 Roland Haeder, this is free software
+ * @copyright  Copyright (c) 2007 - 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
  * @license            GNU GPL 3.0 or any newer version
  *
  * This program is free software: you can redistribute it and/or modify
@@ -30,18 +30,24 @@ function hub_exception_handler ($exceptionInstance) {
                $trace = $exceptionInstance->getTrace();
 
                // Get 3 call levels
-               $backTrace = "";
+               $backTrace = '';
                for ($idx = 0; $idx < 3; $idx++) {
+                       // Copy array for argument analysis and init variable
                        $traceArray = $trace[$idx];
+                       $argsString = '';
 
                        // Convert arguments type into human-readable
-                       $args = $traceArray['args'];
-                       $argsString = "";
-                       foreach ($args as $arg) {
-                               $argsString .= ", ".gettype($arg);
-                       }
+                       foreach ($traceArray['args'] as $arg) {
+                               $argsString .= ', ' . gettype($arg);
+                       } // END - foreach
                        $argsString = substr($argsString, 2);
 
+                       // Set missing file/line
+                       if (!isset($traceArray['file']))  $traceArray['file']  = 'unknown';
+                       if (!isset($traceArray['line']))  $traceArray['line']  = '0';
+                       if (!isset($traceArray['class'])) $traceArray['class'] = 'UnknownObject';
+                       if (!isset($traceArray['type']))  $traceArray['type']  = '->';
+
                        $backTrace .= sprintf("---------- Pos %d: ----------
 Method : %s%s%s(%s)
 ----- Caller: -----
@@ -55,7 +61,7 @@ Line   : %d\n",
                                basename($traceArray['file']),
                                $traceArray['line']
                        );
-               }
+               } // END - for
 
                // Construct the message
                $message = sprintf("--------------------------------------------------------------------------------
@@ -79,12 +85,57 @@ Backtrace:
                );
 
                // Output the message
-               print $message;
+               print($message);
+       } else {
+               // Invalid exception instance detected! Do *only* throw exceptions that
+               // extends our own exception 'FrameworkException' to get such nice
+               // outputs like above.
+               print("exceptionInstance is invalid! Please inform the core developer team.\n");
        }
 }
 
+// Error handler
+function __errorHandler ($errno, $errstr, $errfile, $errline, array $errcontext) {
+       // Construct the message
+       $message = sprintf("File: %s, Line: %s, Code: %s, Message: %s",
+               basename($errfile),
+               $errline,
+               $errno,
+               $errstr
+       );
+
+       // Throw an exception here
+       throw new FatalErrorException($message, BaseFrameworkSystem::EXCEPTION_FATAL_ERROR);
+} // END - function
+
+// Assertion handler
+function __assertHandler ($file, $line, $code) {
+       // Empty code?
+       if ($code === '') $code = '<em>Unknown</em>';
+
+       // Create message
+       $message = sprintf("File: %s, Line: %s, Code: %s",
+               basename($file),
+               $line,
+               $code
+       );
+
+       // Throw an exception here
+       throw new AssertionException($message, BaseFrameworkSystem::EXCEPTION_ASSERTION_FAILED);
+} // END - function
+
+// Set error handler
+//set_error_handler('__errorHandler');
+
 // Set the new handler
 set_exception_handler('hub_exception_handler');
 
+// Init assert handling
+assert_options(ASSERT_ACTIVE,     1);
+assert_options(ASSERT_WARNING,    0);
+assert_options(ASSERT_BAIL,       0);
+assert_options(ASSERT_QUIET_EVAL, 0);
+assert_options(ASSERT_CALLBACK,   '__assertHandler');
+
 // [EOF]
 ?>