<?php
+// Import framework stuff
+use Org\Mxchange\CoreFramework\Assertion\AssertionException;
+use Org\Mxchange\CoreFramework\Error\FatalErrorException;
+use Org\Mxchange\CoreFramework\Generic\FrameworkException;
+use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
+
/**
- * An include file for setting up the exception handler of the lfdb2
+ * An include file for setting up the exception handler of test suite
*
* @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0
- * @copyright Copyright (c) 2013 LFDB2 Developer Team
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2022 LFDB2 Developer Team
* @license GNU GPL 3.0 or any newer version
*
* This program is free software: you can redistribute it and/or modify
// The node's own exception handler
function lfdb2_exception_handler ($exceptionInstance) {
// Is it an object and a valid instance?
- if ((is_object($exceptionInstance)) && ($exceptionInstance instanceof FrameworkException)) {
+ if ((is_object($exceptionInstance)) && ($exceptionInstance instanceof Exception)) {
// Init variable
$backTrace = '';
// Convert arguments type into human-readable
foreach ($traceArray['args'] as $arg) {
$argsString .= ', ' . gettype($arg);
- } // END - foreach
+ }
$argsString = substr($argsString, 2);
// Set missing file/line
basename($traceArray['file']),
$traceArray['line']
);
- } // END - foreach
+ }
// Construct the message
$message = sprintf("--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
%s
--------------------------------------------------------------------------------\n",
- trim(html_entity_decode(strip_tags($exceptionInstance->__toString()))),
+ trim(html_entity_decode(strip_tags(get_class($exceptionInstance)))),
trim(html_entity_decode(strip_tags($exceptionInstance->getMessage()))),
- $exceptionInstance->getHexCode(),
+ ($exceptionInstance instanceof FrameworkException ? $exceptionInstance->getHexCode() : '0x' . bin2hex($exceptionInstance->getCode())),
$exceptionInstance->getFile(),
$exceptionInstance->getLine(),
trim($backTrace)
// Output the message
print($message);
+ } elseif (is_object($exceptionInstance)) {
+ // Output more details
+ printf('exceptionInstance=%s', print_r($exceptionInstance, true));
} 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.');
+ /*
+ * Invalid exception instance detected! Do *only* throw exceptions that
+ * extends our own exception 'FrameworkException' to get such nice
+ * outputs like above.
+ */
+ printf('exceptionInstance[]=%s is invalid! Please inform the core developer team.' . PHP_EOL, gettype($exceptionInstance));
}
}
// Error handler
-function __errorHandler ($errno, $errstr, $errfile, $errline, array $errcontext) {
+function lfdb2_error_handler ($errno, $errstr, $errfile, $errline, array $errcontext) {
// Construct the message
$message = sprintf('File: %s, Line: %s, Code: %s, Message: %s',
basename($errfile),
// Throw an exception here
throw new FatalErrorException($message, BaseFrameworkSystem::EXCEPTION_FATAL_ERROR);
-} // END - function
+}
// Assertion handler
-function __assertHandler ($file, $line, $code) {
+function lfdb2_assert_handler (string $file, int $line, $code) {
// Empty code?
if ($code === '') {
$code = '<em>Unknown</em>';
- } // END - if
+ }
// Create message
$message = sprintf('File: %s, Line: %s, Code: %s',
$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_error_handler('lfdb2_error_handler');
// Set the new handler
set_exception_handler('lfdb2_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');
+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 , 'lfdb2_assert_handler');