X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=application%2Fhub%2Fexceptions.php;h=8eefa5ea554366f8fac8de19fb38fe3620982521;hb=f6368b592b8d4082f856002f6550f37bcfeeea83;hp=340266b067dea208f239b04b44fcf38be8a3a355;hpb=c13ca7c93ee55b02d1d3320fca5d2d8d6e953768;p=hub.git diff --git a/application/hub/exceptions.php b/application/hub/exceptions.php index 340266b06..8eefa5ea5 100644 --- a/application/hub/exceptions.php +++ b/application/hub/exceptions.php @@ -2,9 +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 - 2012 Hub Developer Team + * @copyright Copyright (c) 2007 - 2008 Roland Haeder, 2009 - 2015 Hub Developer Team * @license GNU GPL 3.0 or any newer version * * This program is free software: you can redistribute it and/or modify @@ -25,21 +25,22 @@ 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(); - - // Get 3 call levels + // Init variable $backTrace = ''; - for ($idx = 0; $idx < 3; $idx++) { - // Copy array for argument analysis and init variable - $traceArray = $trace[$idx]; + + // 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); - } // END - foreach - $argsString = substr($argsString, 2); + // Any arguments? + if ((isset($traceArray['args'])) && (is_array($traceArray['args'])) && (count($traceArray['args']) > 0)) { + // Convert arguments type into human-readable + foreach ($traceArray['args'] as $arg) { + $argsString .= ', ' . gettype($arg); + } // END - foreach + $argsString = substr($argsString, 2); + } // END - if // Set missing file/line if (!isset($traceArray['file'])) $traceArray['file'] = 'unknown'; @@ -60,7 +61,7 @@ Line : %d\n", basename($traceArray['file']), $traceArray['line'] ); - } // END - for + } // END - foreach // Construct the message $message = sprintf("-------------------------------------------------------------------------------- @@ -86,17 +87,19 @@ Backtrace: // Output the 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"); + /* + * Invalid exception instance detected! Do *only* throw exceptions that + * extends our own exception 'FrameworkException' to get such nice + * outputs like above. + */ + 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", + $message = sprintf('File: %s, Line: %s, Code: %s, Message: %s', basename($errfile), $errline, $errno, @@ -115,12 +118,16 @@ function __assertHandler ($file, $line, $code) { } // END - if // Create message - $message = sprintf("File: %s, Line: %s, Code: %s", + $message = sprintf('File: %s, Line: %s, Code: %s', basename($file), $line, $code ); + // Log assert + die($message . PHP_EOL); + syslog(LOG_WARNING, $message); + // Throw an exception here throw new AssertionException($message, BaseFrameworkSystem::EXCEPTION_ASSERTION_FAILED); } // END - function @@ -128,15 +135,17 @@ function __assertHandler ($file, $line, $code) { // Set error handler //set_error_handler('__errorHandler'); -// Set the new handler +// Set the exception handler set_exception_handler('hub_exception_handler'); // Init assert handling -assert_options(ASSERT_ACTIVE, true); -assert_options(ASSERT_WARNING, false); -assert_options(ASSERT_BAIL, false); -assert_options(ASSERT_QUIET_EVAL, false); -assert_options(ASSERT_CALLBACK, '__assertHandler'); +assert_options(ASSERT_ACTIVE , TRUE); +assert_options(ASSERT_WARNING , FALSE); +assert_options(ASSERT_BAIL , TRUE); +assert_options(ASSERT_QUIET_EVAL, FALSE); + +// Set assertion handler +assert_options(ASSERT_CALLBACK , '__assertHandler'); // [EOF] ?>