/** * Renders a report to a logfile. * * Do not call directly but use a combination of <log_start_report> and <log_report> instead. * @return void */ public function render() { $lines = array($this->Name . " (" . count($this->Lines) . " lines):"); foreach ($this->Lines as $i => $l) { $line = array("[#" . ($i + 1) . "]"); foreach ($l as $k => $v) { $line[] = logging_render_var($v); } $lines[] = implode("\t", $line); } return implode("\n", $lines); }
/** * Use this to throw exceptions the easy way. * * Can be used from derivered classes too like this: * <code php> * ToDoException::Raise('implement myclass->mymethod()'); * </code> * @return void */ public static function Raise() { $msgs = array(); $inner_exception = false; foreach (func_get_args() as $m) { if (!$inner_exception && $m instanceof Exception) { $inner_exception = $m; } else { $msgs[] = logging_render_var($m); } } $message = implode("\t", $msgs); $classname = get_called_class(); if ($inner_exception) { throw new $classname($message, $inner_exception->getCode(), $inner_exception); } else { throw new $classname($message); } }
/** * Terminats the current run. * * Will be called from exception and error handlers. You may, call this directly, but we * recommend to throw an exception instead. See the WdfException class and it's Raise() method * for more about this. * Note: This function will call `die()`! * @param string $reason The reason as human readable and hopefully understandable text * @param string $additional_message More details to be logged * @return void */ function system_die($reason, $additional_message = '') { if ($reason instanceof Exception) { $stacktrace = $reason instanceof WdfException ? $reason->getTraceEx() : $reason->getTrace(); $reason = logging_render_var($reason); } if (!isset($stacktrace)) { $stacktrace = debug_backtrace(); } if (isset($GLOBALS['system']['hooks'][HOOK_SYSTEM_DIE]) && count($GLOBALS['system']['hooks'][HOOK_SYSTEM_DIE]) > 0) { execute_hooks(HOOK_SYSTEM_DIE, array($reason, $stacktrace)); } if (system_is_ajax_call()) { $res = AjaxResponse::Error($reason . "\n" . $additional_message, true); die($res->Render()); // $code = "alert(unescape(".json_encode($reason."\n".$additional_message)."));"; // $res = new stdClass(); // $res->html = "<script>$code</script>"; // die(system_to_json($res)); } else { $stacktrace = system_stacktrace_to_string($stacktrace); $res = "<html><head><title>Fatal system error</title></head>"; $res .= "<body>"; $res .= "<h1>Fatal system error occured</h1>"; if (isDev()) { $res .= "<pre>{$reason}</pre><pre>{$additional_message}</pre><pre>" . $stacktrace . "</pre>"; } else { $res .= "Fatal System Error occured.<br/>Please try again.<br/>Contact our technical support if this problem occurs again.<br/><br/>Apologies for any inconveniences this may have caused you."; } $res .= "</body></html>"; die($res); } }
/** * @shortcut <logging_render_var> */ function render_var($content) { return logging_render_var($content); }