* @version 0.0 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team * @license GNU GPL 3.0 or any newer version * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ // The node's own exception handler function tests_exception_handler ($exceptionInstance) { // Is it an object and a valid instance? if ((is_object($exceptionInstance)) && ($exceptionInstance instanceof FrameworkException)) { // Init variable $backTrace = ''; // 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); // 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: ----- File : %s Line : %d\n", ($idx + 1), $traceArray['class'], $traceArray['type'], $traceArray['function'], $argsString, basename($traceArray['file']), $traceArray['line'] ); } // END - foreach // Construct the message $message = sprintf("-------------------------------------------------------------------------------- Uncaught Exception : %s -------------------------------------------------------------------------------- Message : %s Code : %s File : %s Line : %d -------------------------------------------------------------------------------- Backtrace: -------------------------------------------------------------------------------- %s --------------------------------------------------------------------------------\n", trim(html_entity_decode(strip_tags($exceptionInstance->__toString()))), trim(html_entity_decode(strip_tags($exceptionInstance->getMessage()))), $exceptionInstance->getHexCode(), $exceptionInstance->getFile(), $exceptionInstance->getLine(), trim($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[]=' . gettype($exceptionInstance) . ' is invalid! Please inform the core developer team.' . PHP_EOL); } } // 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 ); // Log assert syslog(LOG_WARNING, $message); // 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('tests_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');