Пример #1
0
    /**
     * onUncaughtException event listener
     *
     * @param iMSCP_Exception_Event $event
     * @return void
     */
    public function onUncaughtException(iMSCP_Exception_Event $event)
    {
        $exception = $event->getException();
        if (iMSCP_Registry::isRegistered('config')) {
            $debug = iMSCP_Registry::get('config')->DEBUG;
        } else {
            $debug = 1;
        }
        if ($debug) {
            $exception = $event->getException();
            $this->message .= sprintf("An exception has been thrown in file %s at line %s:\n\n", $exception->getFile(), $exception->getLine());
            $this->message .= preg_replace('#([\\t\\n]+|<br \\/>)#', ' ', $exception->getMessage());
            /** @var $exception iMSCP_Exception_Database */
            if ($exception instanceof iMSCP_Exception_Database) {
                $query = $exception->getQuery();
                if ($query !== '') {
                    $this->message .= sprintf("<br><br><strong>Query was:</strong><br><br>%s", $exception->getQuery());
                }
            }
        } else {
            $exception = new iMSCP_Exception_Production($exception->getMessage(), $exception->getCode(), $exception);
            $this->message = $exception->getMessage();
        }
        try {
            if ($this->templateFile) {
                $this->render();
            }
        } catch (Exception $event) {
        }
        # Fallback to inline template in case something goes wrong with template engine
        if (!($tpl = $this->templateEngine)) {
            echo <<<HTML
<!DOCTYPE html>
<html>
\t<head>
\t<title>i-MSCP - internet Multi Server Control Panel - Fatal Error</title>
\t<meta charset="UTF-8">
\t<meta name="robots" content="nofollow, noindex">
\t<link rel="icon" href="/themes/default/assets/images/favicon.ico">
\t<link rel="stylesheet" href="/themes/default/assets/css/jquery-ui-black.css">
\t<link rel="stylesheet" href="/themes/default/assets/css/simple.css">
\t<!--[if (IE 7)|(IE 8)]>
\t\t<link href="/themes/default/assets/css/ie78overrides.css?v=1425280612" rel="stylesheet">
\t<![endif]-->
\t<script src="/themes/default/assets/js/jquery/jquery.js"></script>
\t<script src="/themes/default/assets/js/jquery/jquery-ui.js"></script>
\t<script src="/themes/default/assets/js/imscp.js"></script>
\t<script>
\t\t\$(function () { iMSCP.initApplication('simple'); });
\t</script>
\t</head>
\t<body class="black">
\t\t<div class="wrapper">
\t\t\t<div id="content">
\t\t\t\t<div id="message_container">
\t\t\t\t\t<h1>An unexpected error occurred</h1>
\t\t\t\t\t<pre>{$this->message}</pre>
\t\t\t\t\t<div class="buttons">
\t\t\t\t\t\t<a class="link_as_button" href="javascript:history.go(-1)" target="_self">Back</a>
\t\t\t\t\t</div>
\t\t\t\t</div>
\t\t\t</div>
\t\t</div>
\t</body>
</html>
HTML;
        } else {
            $event->setParam('templateEngine', $tpl);
            layout_init($event);
            $tpl->parse('LAYOUT', 'layout');
            $tpl->prnt();
        }
    }