Skip to content

Commit

Permalink
BlueScreen: refactoring, added formatMessage()
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 8, 2020
1 parent 86b0183 commit 1992008
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions src/Tracy/BlueScreen/BlueScreen.php
Expand Up @@ -113,23 +113,7 @@ public function renderToFile(\Throwable $exception, string $file): bool

private function renderTemplate(\Throwable $exception, string $template, $toScreen = true): void
{
$messageHtml = Dumper::encodeString((string) $exception->getMessage(), self::MAX_MESSAGE_LENGTH);
$messageHtml = htmlspecialchars($messageHtml, ENT_SUBSTITUTE, 'UTF-8');
$messageHtml = preg_replace(
'#\'\S(?:[^\']|\\\\\')*\S\'|"\S(?:[^"]|\\\\")*\S"#',
'<i>$0</i>',
$messageHtml
);
$messageHtml = preg_replace_callback(
'#\w+\\\\[\w\\\\]+\w#',
function ($m) {
return class_exists($m[0], false) || interface_exists($m[0], false)
? '<a href="' . Helpers::escapeHtml(Helpers::editorUri((new \ReflectionClass($m[0]))->getFileName())) . '">' . $m[0] . '</a>'
: $m[0];
},
$messageHtml
);

$messageHtml = $this->formatMessage($exception);
$info = array_filter($this->info);
$source = Helpers::getSource();
$title = $exception instanceof \ErrorException
Expand Down Expand Up @@ -384,4 +368,29 @@ public function getDumper(): \Closure
]);
};
}


private function formatMessage(\Throwable $exception): string
{
$msg = Dumper::encodeString((string) $exception->getMessage(), self::MAX_MESSAGE_LENGTH);
$msg = htmlspecialchars($msg, ENT_SUBSTITUTE, 'UTF-8');

$msg = preg_replace(
'#\'\S(?:[^\']|\\\\\')*\S\'|"\S(?:[^"]|\\\\")*\S"#',
'<i>$0</i>',
$msg
);

$msg = preg_replace_callback(
'#\w+\\\\[\w\\\\]+\w#',
function ($m) {
return class_exists($m[0], false) || interface_exists($m[0], false)
? '<a href="' . Helpers::escapeHtml(Helpers::editorUri((new \ReflectionClass($m[0]))->getFileName())) . '">' . $m[0] . '</a>'
: $m[0];
},
$msg
);

return $msg;
}
}

0 comments on commit 1992008

Please sign in to comment.