X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=application%2Fhub%2Fexceptions.php;h=38ca4bbd29f0e1b27414146e00fd9324715e3248;hb=8f21caa3cca5ee6e4f4a6f786c50851a4d3cc559;hp=f098d06689d36b3b6098fd54eb24f720ec8e3a40;hpb=791ac5766fd11b0843ad4a7c19e922493da13ced;p=hub.git diff --git a/application/hub/exceptions.php b/application/hub/exceptions.php index f098d0668..38ca4bbd2 100644 --- a/application/hub/exceptions.php +++ b/application/hub/exceptions.php @@ -2,10 +2,9 @@ /** * An include file for setting up the exception handler of the hub * - * - * @author Roland Haeder + * @author Roland Haeder * @version 0.0 - * @copyright Copyright (c) 2007 - 2008 Roland Haeder, 2009 Hub Developer Team + * @copyright Copyright (c) 2007 - 2008 Roland Haeder, 2009 - 2012 Hub Developer Team * @license GNU GPL 3.0 or any newer version * * This program is free software: you can redistribute it and/or modify @@ -22,29 +21,29 @@ * along with this program. If not, see . */ -// The hub's own exception handler +// The node's own exception handler function hub_exception_handler ($exceptionInstance) { // Is it an object and a valid instance? if ((is_object($exceptionInstance)) && ($exceptionInstance instanceof FrameworkException)) { - // Get the regular trace - $trace = $exceptionInstance->getTrace(); + // Init variable + $backTrace = ''; - // Get 3 call levels - $backTrace = ""; - for ($idx = 0; $idx < 3; $idx++) { - // Copy array for argument analysis and init variable - $traceArray = $trace[$idx]; - $argsString = ""; + // Get all call levels from backtrace + foreach ($exceptionInstance->getTrace() as $idx => $traceArray) { + // Init argument string + $argsString = ''; // Convert arguments type into human-readable foreach ($traceArray['args'] as $arg) { - $argsString .= ", " . gettype($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'] = 'unknown'; + 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) @@ -59,7 +58,7 @@ Line : %d\n", basename($traceArray['file']), $traceArray['line'] ); - } // END - for + } // END - foreach // Construct the message $message = sprintf("-------------------------------------------------------------------------------- @@ -88,12 +87,54 @@ Backtrace: // 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"); + print('exceptionInstance[]=' . gettype($exceptionInstance) . ' is invalid! Please inform the core developer team.'); } } +// 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 = 'Unknown'; + } // END - if + + // 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 , TRUE); +assert_options(ASSERT_WARNING , FALSE); +assert_options(ASSERT_BAIL , TRUE); +assert_options(ASSERT_QUIET_EVAL, FALSE); +assert_options(ASSERT_CALLBACK , '__assertHandler'); + // [EOF] ?>