- $backtraceArray = debug_backtrace();
- $backtrace = "";
- foreach ($backtraceArray as $key=>$trace) {
- if (!isset($trace['file'])) $trace['file'] = __FILE__;
- if (!isset($trace['line'])) $trace['line'] = __LINE__;
- if (!isset($trace['args'])) $trace['args'] = array();
- $backtrace .= "<span class=\"backtrace_file\">".basename($trace['file'])."</span>:".$trace['line'].", <span class=\"backtrace_function\">".$trace['function']."(".count($trace['args']).")</span><br />";
- } // END - foreach
-
- // Assign variables
- $templateInstance->assignVariable('message', $message);
- $templateInstance->assignVariable('code', $code);
- $templateInstance->assignVariable('extra', $extraData);
- $templateInstance->assignVariable('backtrace', $backtrace);
- $templateInstance->assignVariable('total_includes', ClassLoader::getInstance()->getTotal());
- $templateInstance->assignVariable('total_objects', ObjectFactory::getTotal());
- $templateInstance->assignVariable('title', $lang->getMessage('emergency_exit_title'));
-
- // Load the template
- $templateInstance->loadCodeTemplate('emergency_exit');
-
- // Compile the template
- $templateInstance->compileTemplate();
-
- // Compile all variables
- $templateInstance->compileVariables();
-
- // Transfer data to response
- $templateInstance->transferToResponse($responseInstance);
-
- // Flush the response
- $responseInstance->flushBuffer();
+ $backtrace = '';
+ foreach (debug_backtrace() as $key => $trace) {
+ // Set missing array elements
+ if (!isset($trace['file'])) {
+ $trace['file'] = __FILE__;
+ }
+ if (!isset($trace['line'])) {
+ $trace['line'] = __LINE__;
+ }
+ if (!isset($trace['args'])) {
+ $trace['args'] = array();
+ }
+
+ // Add the traceback path to the final output
+ $backtrace .= sprintf('<span class="backtrace_file">%s</span>:%d, <span class="backtrace_function">%s(%d)</span><br />' . PHP_EOL,
+ basename($trace['file']),
+ $trace['line'],
+ $trace['function'],
+ count($trace['args'])
+ );
+ }
+
+ // Init application instance
+ $applicationInstance = NULL;
+
+ /*
+ * The following class may NOT be loaded at all times. For example,
+ * it might be the (rare) case that an error has happened BEFORE
+ * that class had been loaded and cannot be loaded or else an
+ * infinte loop in invoking this method will take place resulting in
+ * a stack-overflow error.
+ */
+ if (class_exists('Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper')) {
+ // Get application instance
+ $applicationInstance = ApplicationHelper::getSelfInstance();
+
+ // Assign application data
+ $templateInstance->assignApplicationData();
+ }
+
+ // We only try this
+ try {
+ // Assign variables
+ $templateInstance->assignVariable('message' , $message);
+ $templateInstance->assignVariable('code' , $code);
+ $templateInstance->assignVariable('extra' , $extraData);
+ $templateInstance->assignVariable('backtrace' , $backtrace);
+ $templateInstance->assignVariable('total_includes', ClassLoader::getSelfInstance()->getTotal());
+ $templateInstance->assignVariable('total_objects' , ObjectFactory::getTotal());
+ $templateInstance->assignVariable('title' , $languageInstance->getMessage('emergency_exit_title'));
+
+ // Load the template
+ $templateInstance->loadCodeTemplate('emergency_exit');
+
+ // Compile the template
+ $templateInstance->compileTemplate();
+
+ // Compile all variables
+ $templateInstance->compileVariables();
+
+ // Transfer data to response
+ $templateInstance->transferToResponse($responseInstance);
+
+ // Flush the response
+ $responseInstance->flushBuffer();
+ } catch (FileNotFoundException $e) {
+ // Even the template 'emergency_exit' wasn't found so output both message
+ print ($message . ', exception: ' . $e->getMessage() . PHP_EOL);
+ exit($e->getCode());
+ }