Skip to content

Commit be4f4ac

Browse files
committed
BlueScreen: keysToHide respected in title [Closes #381]
1 parent 9f3b88f commit be4f4ac

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/Tracy/BlueScreen/BlueScreen.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,11 @@ private function renderActions(\Throwable $ex): array
240240
/**
241241
* Returns syntax highlighted source code.
242242
*/
243-
public static function highlightFile(string $file, int $line, int $lines = 15, array $vars = []): ?string
243+
public static function highlightFile(string $file, int $line, int $lines = 15, array $vars = [], array $keysToHide = []): ?string
244244
{
245245
$source = @file_get_contents($file); // @ file may not exist
246246
if ($source) {
247-
$source = static::highlightPhp($source, $line, $lines, $vars);
247+
$source = static::highlightPhp($source, $line, $lines, $vars, $keysToHide);
248248
if ($editor = Helpers::editorUri($file, $line)) {
249249
$source = substr_replace($source, ' data-tracy-href="' . Helpers::escapeHtml($editor) . '"', 4, 0);
250250
}
@@ -256,7 +256,7 @@ public static function highlightFile(string $file, int $line, int $lines = 15, a
256256
/**
257257
* Returns syntax highlighted source code.
258258
*/
259-
public static function highlightPhp(string $source, int $line, int $lines = 15, array $vars = []): string
259+
public static function highlightPhp(string $source, int $line, int $lines = 15, array $vars = [], array $keysToHide = []): string
260260
{
261261
if (function_exists('ini_set')) {
262262
ini_set('highlight.comment', '#998; font-style: italic');
@@ -273,12 +273,15 @@ public static function highlightPhp(string $source, int $line, int $lines = 15,
273273
$out .= static::highlightLine($source, $line, $lines);
274274

275275
if ($vars) {
276-
$out = preg_replace_callback('#">\$(\w+)(&nbsp;)?</span>#', function (array $m) use ($vars): string {
277-
return array_key_exists($m[1], $vars)
278-
? '" title="'
279-
. str_replace('"', '&quot;', trim(strip_tags(Dumper::toHtml($vars[$m[1]], [Dumper::DEPTH => 1]))))
280-
. $m[0]
281-
: $m[0];
276+
$out = preg_replace_callback('#">\$(\w+)(&nbsp;)?</span>#', function (array $m) use ($vars, $keysToHide): string {
277+
if (array_key_exists($m[1], $vars)) {
278+
$dump = Dumper::toHtml($vars[$m[1]], [
279+
Dumper::DEPTH => 1,
280+
Dumper::KEYS_TO_HIDE => $keysToHide,
281+
]);
282+
return '" title="' . str_replace('"', '&quot;', trim(strip_tags($dump))) . $m[0];
283+
}
284+
return $m[0];
282285
}, $out);
283286
}
284287

src/Tracy/BlueScreen/assets/content.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ $code = $exception->getCode() ? ' #' . $exception->getCode() : '';
8383

8484
<div class="<?= $collapsed ? 'tracy-collapsed ' : '' ?>inner">
8585
<p><b>File:</b> <?= Helpers::editorLink($ex->getFile(), $ex->getLine()) ?></p>
86-
<?php if (is_file($ex->getFile())): ?><?= self::highlightFile($ex->getFile(), $ex->getLine(), 15, $ex instanceof \ErrorException && isset($ex->context) ? $ex->context : []) ?><?php endif ?>
86+
<?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 ?>
8787
</div></div>
8888

8989

0 commit comments

Comments
 (0)