From 84682eaa03f0318a469bba6195def62e5d8e4d41 Mon Sep 17 00:00:00 2001 From: Pavinthan Date: Fri, 6 Sep 2019 13:14:23 +0530 Subject: [PATCH 1/2] [VarDumper] Display fully qualified title --- src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php b/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php index 1eb02bcbee8af..4a0cd8a8c693f 100644 --- a/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php +++ b/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php @@ -884,14 +884,14 @@ protected function style($style, $value, $attr = []) $style .= sprintf(' title="%s"', empty($attr['dynamic']) ? 'Public property' : 'Runtime added dynamic property'); } elseif ('str' === $style && 1 < $attr['length']) { $style .= sprintf(' title="%d%s characters"', $attr['length'], $attr['binary'] ? ' binary or non-UTF-8' : ''); - } elseif ('note' === $style && false !== $c = strrpos($v, '\\')) { + } elseif ('note' === $style && false !== strrpos($v, '\\')) { if (isset($attr['file']) && $link = $this->getSourceLink($attr['file'], isset($attr['line']) ? $attr['line'] : 0)) { $link = sprintf('^', esc($this->utf8Encode($link))); } else { $link = ''; } - return sprintf('%s%s', $v, $style, substr($v, $c + 1), $link); + return sprintf('%s%s', $v, $style, $v, $link); } elseif ('protected' === $style) { $style .= ' title="Protected property"'; } elseif ('meta' === $style && isset($attr['title'])) { From a8252a23ff0a4d171392479c3ad1b4a02b1cda2a Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 7 Sep 2019 13:21:11 +0200 Subject: [PATCH 2/2] [VarDumper] display ellipsed FQCN for nested classes --- .../Component/VarDumper/Dumper/HtmlDumper.php | 40 ++++++++++--------- .../Tests/Caster/ExceptionCasterTest.php | 4 +- .../VarDumper/Tests/Caster/StubCasterTest.php | 2 +- .../VarDumper/Tests/Dumper/HtmlDumperTest.php | 13 +++--- 4 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php b/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php index 4a0cd8a8c693f..e7a6e32f30acf 100644 --- a/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php +++ b/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php @@ -319,12 +319,16 @@ function a(e, f) { f(e.target, e); } else if ('A' == e.target.parentNode.tagName) { f(e.target.parentNode, e); - } else if ((n = e.target.nextElementSibling) && 'A' == n.tagName) { - if (!/\bsf-dump-toggle\b/.test(n.className)) { - n = n.nextElementSibling; - } + } else { + n = /\bsf-dump-ellipsis\b/.test(e.target.className) ? e.target.parentNode : e.target; + + if ((n = n.nextElementSibling) && 'A' == n.tagName) { + if (!/\bsf-dump-toggle\b/.test(n.className)) { + n = n.nextElementSibling || n; + } - f(n, e, true); + f(n, e, true); + } } }); }; @@ -670,11 +674,6 @@ function showCurrent(state) pre.sf-dump .sf-dump-compact { display: none; } -pre.sf-dump abbr { - text-decoration: none; - border: none; - cursor: help; -} pre.sf-dump a { text-decoration: none; cursor: pointer; @@ -795,6 +794,7 @@ function showCurrent(state) foreach ($this->styles as $class => $style) { $line .= 'pre.sf-dump'.('default' === $class ? ', pre.sf-dump' : '').' .sf-dump-'.$class.'{'.$style.'}'; } + $line .= 'pre.sf-dump .sf-dump-ellipsis-note{'.$this->styles['note'].'}'; return $this->dumpHeader = preg_replace('/\s+/', ' ', $line).''.$this->dumpHeader; } @@ -821,6 +821,9 @@ public function dumpString(Cursor $cursor, $str, $bin, $cut) */ public function enterHash(Cursor $cursor, $type, $class, $hasChild) { + if (Cursor::HASH_OBJECT === $type) { + $cursor->attr['depth'] = $cursor->depth; + } parent::enterHash($cursor, $type, $class, false); if ($cursor->skipChildren) { @@ -884,14 +887,13 @@ protected function style($style, $value, $attr = []) $style .= sprintf(' title="%s"', empty($attr['dynamic']) ? 'Public property' : 'Runtime added dynamic property'); } elseif ('str' === $style && 1 < $attr['length']) { $style .= sprintf(' title="%d%s characters"', $attr['length'], $attr['binary'] ? ' binary or non-UTF-8' : ''); - } elseif ('note' === $style && false !== strrpos($v, '\\')) { - if (isset($attr['file']) && $link = $this->getSourceLink($attr['file'], isset($attr['line']) ? $attr['line'] : 0)) { - $link = sprintf('^', esc($this->utf8Encode($link))); - } else { - $link = ''; - } - - return sprintf('%s%s', $v, $style, $v, $link); + } elseif ('note' === $style && 0 < ($attr['depth'] ?? 0) && false !== $c = strrpos($value, '\\')) { + $style .= ' title=""'; + $attr += [ + 'ellipsis' => \strlen($value) - $c, + 'ellipsis-type' => 'note', + 'ellipsis-tail' => 1, + ]; } elseif ('protected' === $style) { $style .= ' title="Protected property"'; } elseif ('meta' === $style && isset($attr['title'])) { @@ -912,7 +914,7 @@ protected function style($style, $value, $attr = []) if (!empty($attr['ellipsis-tail'])) { $tail = \strlen(esc(substr($value, -$attr['ellipsis'], $attr['ellipsis-tail']))); - $v .= sprintf('%s%s', substr($label, 0, $tail), substr($label, $tail)); + $v .= sprintf('%s%s', $class, substr($label, 0, $tail), substr($label, $tail)); } else { $v .= $label; } diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/ExceptionCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/ExceptionCasterTest.php index 762597707eaef..1096919308b55 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/ExceptionCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/ExceptionCasterTest.php @@ -142,11 +142,11 @@ public function testHtmlDump() #message: "1" #code: 0 #file: "%s%eVarDumper%eTests%eCaster%eExceptionCasterTest.php" +%d characters">%s%eVarDumper%eTests%eCaster%eExceptionCasterTest.php" #line: 28 trace: { %s%eVarDumper%eTests%eCaster%eExceptionCasterTest.php:28 +Stack level %d.">%s%eVarDumper%eTests%eCaster%eExceptionCasterTest.php:28 …%d } } diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/StubCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/StubCasterTest.php index 8056f703b60bb..ebbf91cda9c8c 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/StubCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/StubCasterTest.php @@ -162,7 +162,7 @@ public function testClassStubWithNotExistingClass() $expectedDump = <<<'EODUMP' array:1 [ 0 => "Symfony\Component\VarDumper\Tests\Caster\NotExisting" +52 characters">Symfony\Component\VarDumper\Tests\Caster\NotExisting" ] EODUMP; diff --git a/src/Symfony/Component/VarDumper/Tests/Dumper/HtmlDumperTest.php b/src/Symfony/Component/VarDumper/Tests/Dumper/HtmlDumperTest.php index 4a8ffdfceb408..b6db08ea9e168 100644 --- a/src/Symfony/Component/VarDumper/Tests/Dumper/HtmlDumperTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Dumper/HtmlDumperTest.php @@ -78,16 +78,18 @@ public function testGet() seekable: true %A options: [] } - "obj" => DumbFoo {#%d + "obj" => Symfony\Component\VarDumper\Tests\Fixture\DumbFoo {#%d +foo: "foo" +"bar": "bar" } "closure" => Closure(\$a, PDO &\$b = null) {#%d class: "Symfony\Component\VarDumper\Tests\Dumper\HtmlDumperTest" - this: HtmlDumperTest {#%d &%s;} +55 characters">Symfony\Component\VarDumper\Tests\Dumper\HtmlDumperTest" + this: Symfony\Component\VarDumper\Tests\Dumper\HtmlDumperTest {#%d &%s;} file: "%s%eVarDumper%eTests%eFixtures%edumb-var.php" +%d characters">%s%eVarDumper%eTests%eFixtures%edumb-var.php" line: "{$var['line']} to {$var['line']}" } "line" => {$var['line']} @@ -98,7 +100,8 @@ public function testGet() 0 => &4 array:1 [&4] ] 8 => &1 null - "sobj" => DumbFoo {#%d} + "sobj" => Symfony\Component\VarDumper\Tests\Fixture\DumbFoo {#%d} "snobj" => &3 {#%d} "snobj2" => {#%d} "file" => "{$var['file']}"