Skip to content

Commit

Permalink
Dumper: hidden values are rendered with type of variable [Closes #380]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Sep 13, 2019
1 parent 76e3f5d commit b4160e3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
15 changes: 8 additions & 7 deletions src/Tracy/BlueScreen/BlueScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,14 @@ public static function highlightPhp(string $source, int $line, int $lines = 15,

if ($vars) {
$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($dump))) . $m[0]
: $m[0];
if (array_key_exists($m[1], $vars)) {
$dump = Dumper::toHtml($vars[$m[1]], [
Dumper::DEPTH => 1,
Dumper::KEYS_TO_HIDE => $keysToHide,
]);
return '" title="' . str_replace('"', '&quot;', trim(strip_tags($dump))) . $m[0];
}
return $m[0];
}, $out);
}

Expand Down
24 changes: 18 additions & 6 deletions src/Tracy/Dumper/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,13 @@ private function dumpArray(&$var, array $options, int $level): string
$out = $span . '>' . $out . count($var) . ")</span>\n" . '<div' . ($collapsed ? ' class="tracy-collapsed"' : '') . '>';
$options['parents'][] = $var;
foreach ($var as $k => &$v) {
$hide = is_string($k) && isset($this->keysToHide[strtolower($k)]) ? self::HIDDEN_VALUE : null;
$hide = is_string($k) && isset($this->keysToHide[strtolower($k)]);
$out .= '<span class="tracy-dump-indent"> ' . str_repeat('| ', $level) . '</span>'
. '<span class="tracy-dump-key">' . Helpers::escapeHtml($this->encodeKey($k)) . '</span> => '
. ($hide ? $this->dumpString($hide) : $this->dumpVar($v, $options, $level + 1));
. ($hide
? Helpers::escapeHtml(self::hideValue($v)) . "\n"
: $this->dumpVar($v, $options, $level + 1)
);
}
array_pop($options['parents']);

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

Expand Down Expand Up @@ -419,7 +425,7 @@ private function toJson(&$var, array $options = [], int $level = 0)
$options['parents'][] = $var;
foreach ($var as $k => &$v) {
$hide = is_string($k) && isset($this->keysToHide[strtolower($k)]);
$res[] = [$this->encodeKey($k), $hide ? self::HIDDEN_VALUE : $this->toJson($v, $options, $level + 1)];
$res[] = [$this->encodeKey($k), $hide ? ['type' => self::hideValue($v)] : $this->toJson($v, $options, $level + 1)];
}
array_pop($options['parents']);
return $res;
Expand Down Expand Up @@ -456,7 +462,7 @@ private function toJson(&$var, array $options = [], int $level = 0)
$k = substr($k, strrpos($k, "\x00") + 1);
}
$hide = is_string($k) && isset($this->keysToHide[strtolower($k)]);
$obj['items'][] = [$this->encodeKey($k), $hide ? self::HIDDEN_VALUE : $this->toJson($v, $options, $level + 1), $vis];
$obj['items'][] = [$this->encodeKey($k), $hide ? ['type' => self::hideValue($v)] : $this->toJson($v, $options, $level + 1), $vis];
}
}
return ['object' => $obj['id']];
Expand Down Expand Up @@ -619,6 +625,12 @@ private static function exportPhpIncompleteClass(\__PHP_Incomplete_Class $obj):
}


private static function hideValue($var): string
{
return self::HIDDEN_VALUE . ' (' . (is_object($var) ? Helpers::getClass($var) : gettype($var)) . ')';
}


/**
* Finds the location where dump was called. Returns [file, line, code]
*/
Expand Down

0 comments on commit b4160e3

Please sign in to comment.