Beispiel #1
0
 public static function exceptionHandler(\Exception $e)
 {
     $fullTrace = $e->getTrace();
     if (is_callable(array($e, 'postAction'))) {
         $e->postAction($e->getMessage(), $e->getCode());
     }
     if (!DC::getProjectConfig('devMode')) {
         DC::getLogger()->add('Exception: ' . $e->getMessage(), 'exception');
         die;
     }
     $content = '<div style="font-size: 13px; font-family: Consolas, Menlo, Monaco, monospace;white-space: pre-wrap;">';
     $htmlTrace = "<b>\nLast arguments(" . count($fullTrace[0]['args']) . "):</b>\n" . dumpAsString($fullTrace[0]['args']) . "<b>\n\nCall stack:</b>\n<table style='font-size: 13px;'>";
     foreach ($fullTrace as $item) {
         $info = self::compileShortCallee($item);
         $htmlTrace .= '<tr><td style="color:#666;padding-right:10px;">' . $info['file'] . '</td><td>' . $info['call'] . '</td></tr>';
     }
     $htmlTrace .= '</table>';
     $content .= '<div style="background:#c00;color:white;font-weight:bold;padding:5px;margin-bottom: 5px; ">' . $e->getMessage() . '</div>';
     $content .= $htmlTrace;
     $content .= '</div>';
     if (DC::getRouter()->getExecutionMode() == Request::MODE_CONSOLE) {
         $content = strip_tags(str_replace('</td><td>', "\n", $content)) . "\n";
     }
     echo $content;
     die;
 }
Beispiel #2
0
function dumpAsString($var, $new_level = 0)
{
    $res = '';
    if (is_bool($var)) {
        $res = $var ? "true" : "false";
    } elseif (is_null($var)) {
        $res = "null";
    } elseif (is_array($var)) {
        $res = 'array (';
        foreach ($var as $key => $item) {
            $res .= "\n" . str_repeat(" ", ($new_level + 1) * 4);
            $res .= dumpAsString($key, $new_level + 1);
            $res .= ' => ';
            $res .= dumpAsString($item, $new_level + 1) . ',';
        }
        $res .= "\n" . str_repeat(" ", $new_level * 4) . ')';
    } elseif (is_string($var) && (isset($var[0]) && $var[0] != '$')) {
        $res = '"' . (strpos($var, '$__lv') === false ? str_replace('"', '\\"', $var) : $var) . '"';
    } else {
        $res = $var;
    }
    return $res;
}