Skip to content

Commit b4160e3

Browse files
committed
Dumper: hidden values are rendered with type of variable [Closes #380]
1 parent 76e3f5d commit b4160e3

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

src/Tracy/BlueScreen/BlueScreen.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,14 @@ public static function highlightPhp(string $source, int $line, int $lines = 15,
274274

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

src/Tracy/Dumper/Dumper.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,13 @@ private function dumpArray(&$var, array $options, int $level): string
297297
$out = $span . '>' . $out . count($var) . ")</span>\n" . '<div' . ($collapsed ? ' class="tracy-collapsed"' : '') . '>';
298298
$options['parents'][] = $var;
299299
foreach ($var as $k => &$v) {
300-
$hide = is_string($k) && isset($this->keysToHide[strtolower($k)]) ? self::HIDDEN_VALUE : null;
300+
$hide = is_string($k) && isset($this->keysToHide[strtolower($k)]);
301301
$out .= '<span class="tracy-dump-indent"> ' . str_repeat('| ', $level) . '</span>'
302302
. '<span class="tracy-dump-key">' . Helpers::escapeHtml($this->encodeKey($k)) . '</span> => '
303-
. ($hide ? $this->dumpString($hide) : $this->dumpVar($v, $options, $level + 1));
303+
. ($hide
304+
? Helpers::escapeHtml(self::hideValue($v)) . "\n"
305+
: $this->dumpVar($v, $options, $level + 1)
306+
);
304307
}
305308
array_pop($options['parents']);
306309

@@ -361,10 +364,13 @@ private function dumpObject(&$var, array $options, int $level): string
361364
$vis = ' <span class="tracy-dump-visibility">' . ($k[1] === '*' ? 'protected' : 'private') . '</span>';
362365
$k = substr($k, strrpos($k, "\x00") + 1);
363366
}
364-
$hide = is_string($k) && isset($this->keysToHide[strtolower($k)]) ? self::HIDDEN_VALUE : null;
367+
$hide = is_string($k) && isset($this->keysToHide[strtolower($k)]);
365368
$out .= '<span class="tracy-dump-indent"> ' . str_repeat('| ', $level) . '</span>'
366369
. '<span class="tracy-dump-key">' . Helpers::escapeHtml($this->encodeKey($k)) . "</span>$vis => "
367-
. ($hide ? $this->dumpString($hide) : $this->dumpVar($v, $options, $level + 1));
370+
. ($hide
371+
? Helpers::escapeHtml(self::hideValue($v)) . "\n"
372+
: $this->dumpVar($v, $options, $level + 1)
373+
);
368374
}
369375
array_pop($options['parents']);
370376

@@ -419,7 +425,7 @@ private function toJson(&$var, array $options = [], int $level = 0)
419425
$options['parents'][] = $var;
420426
foreach ($var as $k => &$v) {
421427
$hide = is_string($k) && isset($this->keysToHide[strtolower($k)]);
422-
$res[] = [$this->encodeKey($k), $hide ? self::HIDDEN_VALUE : $this->toJson($v, $options, $level + 1)];
428+
$res[] = [$this->encodeKey($k), $hide ? ['type' => self::hideValue($v)] : $this->toJson($v, $options, $level + 1)];
423429
}
424430
array_pop($options['parents']);
425431
return $res;
@@ -456,7 +462,7 @@ private function toJson(&$var, array $options = [], int $level = 0)
456462
$k = substr($k, strrpos($k, "\x00") + 1);
457463
}
458464
$hide = is_string($k) && isset($this->keysToHide[strtolower($k)]);
459-
$obj['items'][] = [$this->encodeKey($k), $hide ? self::HIDDEN_VALUE : $this->toJson($v, $options, $level + 1), $vis];
465+
$obj['items'][] = [$this->encodeKey($k), $hide ? ['type' => self::hideValue($v)] : $this->toJson($v, $options, $level + 1), $vis];
460466
}
461467
}
462468
return ['object' => $obj['id']];
@@ -619,6 +625,12 @@ private static function exportPhpIncompleteClass(\__PHP_Incomplete_Class $obj):
619625
}
620626

621627

628+
private static function hideValue($var): string
629+
{
630+
return self::HIDDEN_VALUE . ' (' . (is_object($var) ? Helpers::getClass($var) : gettype($var)) . ')';
631+
}
632+
633+
622634
/**
623635
* Finds the location where dump was called. Returns [file, line, code]
624636
*/

0 commit comments

Comments
 (0)