Skip to content
Permalink
Browse files

BlueScreen: keysToHide respected in title [Closes #381]

  • Loading branch information...
dg committed Aug 30, 2019
1 parent 9f3b88f commit a6aaefb7317d490c627a39858f9a1c8a30c2e6ea
Showing with 10 additions and 8 deletions.
  1. +9 −7 src/Tracy/BlueScreen/BlueScreen.php
  2. +1 −1 src/Tracy/BlueScreen/assets/content.phtml
@@ -240,11 +240,11 @@ private function renderActions(\Throwable $ex): array
/**
* Returns syntax highlighted source code.
*/
public static function highlightFile(string $file, int $line, int $lines = 15, array $vars = []): ?string
public static function highlightFile(string $file, int $line, int $lines = 15, array $vars = [], array $keysToHide = []): ?string
{
$source = @file_get_contents($file); // @ file may not exist
if ($source) {
$source = static::highlightPhp($source, $line, $lines, $vars);
$source = static::highlightPhp($source, $line, $lines, $vars, $keysToHide);
if ($editor = Helpers::editorUri($file, $line)) {
$source = substr_replace($source, ' data-tracy-href="' . Helpers::escapeHtml($editor) . '"', 4, 0);
}
@@ -256,7 +256,7 @@ public static function highlightFile(string $file, int $line, int $lines = 15, a
/**
* Returns syntax highlighted source code.
*/
public static function highlightPhp(string $source, int $line, int $lines = 15, array $vars = []): string
public static function highlightPhp(string $source, int $line, int $lines = 15, array $vars = [], array $keysToHide = []): string
{
if (function_exists('ini_set')) {
ini_set('highlight.comment', '#998; font-style: italic');
@@ -273,11 +273,13 @@ public static function highlightPhp(string $source, int $line, int $lines = 15,
$out .= static::highlightLine($source, $line, $lines);
if ($vars) {
$out = preg_replace_callback('#">\$(\w+)(&nbsp;)?</span>#', function (array $m) use ($vars): string {
$out = preg_replace_callback('#">\$(\w+)(&nbsp;)?</span>#', function (array $m) use ($vars, $keysToHide): string {
$dump = Dumper::toHtml($vars[$m[1]], [
Dumper::DEPTH => 1,
Dumper::KEYS_TO_HIDE => $keysToHide,
]);
return array_key_exists($m[1], $vars)
? '" title="'
. str_replace('"', '&quot;', trim(strip_tags(Dumper::toHtml($vars[$m[1]], [Dumper::DEPTH => 1]))))
. $m[0]
? '" title="' . str_replace('"', '&quot;', trim(strip_tags($dump))) . $m[0]
: $m[0];
}, $out);
}
@@ -83,7 +83,7 @@ $code = $exception->getCode() ? ' #' . $exception->getCode() : '';

<div class="<?= $collapsed ? 'tracy-collapsed ' : '' ?>inner">
<p><b>File:</b> <?= Helpers::editorLink($ex->getFile(), $ex->getLine()) ?></p>
<?php if (is_file($ex->getFile())): ?><?= self::highlightFile($ex->getFile(), $ex->getLine(), 15, $ex instanceof \ErrorException && isset($ex->context) ? $ex->context : []) ?><?php endif ?>
<?php if (is_file($ex->getFile())): ?><?= self::highlightFile($ex->getFile(), $ex->getLine(), 15, $ex instanceof \ErrorException && isset($ex->context) ? $ex->context : [], $this->keysToHide) ?><?php endif ?>
</div></div>


0 comments on commit a6aaefb

Please sign in to comment.
You can’t perform that action at this time.