/** * The render function will take a `DatabaseException` and output a * HTML page. * * @param DatabaseException $e * The Exception object * @return string * An HTML string */ public static function render(Exception $e) { $trace = NULL; foreach ($e->getTrace() as $t) { $trace .= sprintf('<li><code><em>[%s:%d]</em></code></li><li><code>    %s%s%s();</code></li>', $t['file'], $t['line'], isset($t['class']) ? $t['class'] : NULL, isset($t['type']) ? $t['type'] : NULL, $t['function']); } $queries = NULL; if (is_object(Symphony::Database())) { $debug = Symphony::Database()->debug(); if (!empty($debug)) { foreach ($debug as $query) { $queries .= sprintf('<li><em>[%01.4f]</em><code> %s;</code> </li>', isset($query['execution_time']) ? $query['execution_time'] : NULL, htmlspecialchars($query['query'])); } } } $html = sprintf(file_get_contents(self::getTemplate('fatalerror.database')), $e->getDatabaseErrorMessage(), $e->getQuery(), $trace, $queries); return str_replace('{SYMPHONY_URL}', SYMPHONY_URL, $html); }
/** * The render function will take a DatabaseException and output a * HTML page. * * @param DatabaseException $e * The Exception object * @return string * An HTML string */ public static function render(Exception $e) { $trace = NULL; $odd = true; foreach ($e->getTrace() as $t) { $trace .= sprintf('<li%s><code>[%s:%d] <strong>%s%s%s();</strong></code></li>', $odd == true ? ' class="odd"' : NULL, $t['file'], $t['line'], isset($t['class']) ? $t['class'] : NULL, isset($t['type']) ? $t['type'] : NULL, $t['function']); $odd = !$odd; } $queries = NULL; $odd = true; if (is_object(Symphony::Database())) { $debug = Symphony::Database()->debug(); if (count($debug['query']) > 0) { foreach ($debug['query'] as $query) { $queries .= sprintf('<li%s><code>%s;</code> <small>[%01.4f]</small></li>', $odd == true ? ' class="odd"' : NULL, htmlspecialchars($query['query']), isset($query['time']) ? $query['time'] : NULL); $odd = !$odd; } } } return sprintf(file_get_contents(TEMPLATE . '/fatalerror.tpl'), $e->getDatabaseErrorMessage(), $e->getQuery(), $trace, $queries); }
/** * @param Neo4j\Exception $e * @return type */ public static function renderException(\Exception $e = null) { if ($e instanceof Neo4j\Exception) { $panel = NULL; if ($e->getQuery() !== null) { $panel .= '<h3>Query</h3>' . '<pre class="nette-dump"><span class="php-string">' . $e->getQuery()->getQuery() . '</span></pre>'; } if ($panel !== NULL) { $panel = array('tab' => 'Neo4j', 'panel' => $panel); } return $panel; } }
/** * Prepare the mail to be send * * @param Exception $exception An exception object * @return array Array containing mail parts */ protected function prepareMail($exception) { $mail = array(); if (iMSCP_Registry::isRegistered('config')) { /** @var iMSCP_Config_Handler_File $config */ $config = iMSCP_Registry::get('config'); if (isset($config['DEFAULT_ADMIN_ADDRESS'])) { $rcptTo = $config['DEFAULT_ADMIN_ADDRESS']; $sender = 'webmaster@' . $config['BASE_SERVER_VHOST']; if (filter_var($rcptTo, FILTER_VALIDATE_EMAIL) !== false) { $mail['rcptTo'] = $rcptTo; $message = preg_replace('#([\\t\\n]+|<br \\/>)#', ' ', $exception->getMessage()); /** @var $exception iMSCP_Exception_Database */ if ($exception instanceof iMSCP_Exception_Database) { $message .= "\n\nQuery was:\n\n" . $exception->getQuery(); } // Header $mail['header'] = 'From: "' . self::NAME . "\" <{$sender}>\n"; $mail['header'] .= "MIME-Version: 1.0\n"; $mail['header'] .= "Content-Type: text/plain; charset=utf-8\n"; $mail['header'] .= "Content-Transfer-Encoding: 8bit\n"; $mail['header'] .= 'X-Mailer: ' . self::NAME; // Subject $mail['subject'] = self::NAME . ' - An exception has been thrown'; // Body $mail['body'] = "Dear admin,\n\n"; $mail['body'] .= sprintf("An exception has been thrown in file %s at line %s:\n\n", $exception->getFile(), $exception->getLine()); $mail['body'] .= str_repeat('=', 65) . "\n\n"; $mail['body'] .= "{$message}\n\n"; $mail['body'] .= str_repeat('=', 65) . "\n\n"; $mail['body'] .= "Debug backtrace:\n"; $mail['body'] .= str_repeat('-', 15) . "\n\n"; if ($traces = $exception->getTrace()) { foreach ($traces as $trace) { if (isset($trace['file'])) { $mail['body'] .= sprintf("File: %s at line %s\n", $trace['file'], $trace['line']); } if (isset($trace['class'])) { $mail['body'] .= sprintf("Method: %s\n", $trace['class'] . '::' . $trace['function'] . '()'); } elseif (isset($trace['function'])) { $mail['body'] .= sprintf("Function: %s\n", $trace['function'] . '()'); } } } else { $mail['body'] .= sprintf("File: %s at line %s\n", $exception->getFile(), $exception->getLine()); $mail['body'] .= "Function: main()\n"; } // Generate mail footprint using static part of mail body $mail['footprint'] = md5($mail['body']); // Additional information $mail['body'] .= "\nAdditional information:\n"; $mail['body'] .= str_repeat('-', 22) . "\n\n"; foreach (array('HTTP_USER_AGENT', 'REQUEST_URI', 'HTTP_REFERER', 'REMOTE_ADDR', 'X-FORWARDED-FOR', 'SERVER_ADDR') as $key) { if (isset($_SERVER[$key]) && $_SERVER[$key] !== '') { $mail['body'] .= ucwords(strtolower(str_replace('_', ' ', $key))) . ": {$_SERVER["{$key}"]}\n"; } } $mail['body'] .= "\n" . str_repeat('_', 60) . "\n"; $mail['body'] .= self::NAME . "\n"; $mail['body'] .= "\n\nNote: You will not receive further emails for such exception in the next 24 hours.\n"; $mail['body'] = wordwrap($mail['body'], 70, "\n"); } } } return $mail; }