From da96719b94fae82ab7fc1c783256f53f47f50975 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 16 Aug 2016 10:16:14 +0200 Subject: [PATCH] [VarDumper] Fix dumping continuations --- .../DataCollector/DumpDataCollector.php | 3 +- .../Component/VarDumper/Dumper/HtmlDumper.php | 16 ++--------- .../VarDumper/Tests/HtmlDumperTest.php | 28 +++++++++++++++++-- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php index c50bf7a135b3..635402e16093 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php @@ -211,8 +211,7 @@ public function getDumps($format, $maxDepthLimit = -1, $maxItemsPerDepth = -1) // getLimitedClone is @deprecated, to be removed in 3.0 $dumper->dump($dump['data']->getLimitedClone($maxDepthLimit, $maxItemsPerDepth)); } - rewind($data); - $dump['data'] = stream_get_contents($data); + $dump['data'] = stream_get_contents($data, -1, 0); ftruncate($data, 0); rewind($data); $dumps[] = $dump; diff --git a/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php b/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php index 43601fe668f5..0b032b71e669 100644 --- a/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php +++ b/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php @@ -54,18 +54,6 @@ public function __construct($output = null, $charset = null) $this->dumpId = 'sf-dump-'.mt_rand(); } - /** - * {@inheritdoc} - */ - public function setOutput($output) - { - if ($output !== $prev = parent::setOutput($output)) { - $this->headerIsDumped = false; - } - - return $prev; - } - /** * {@inheritdoc} */ @@ -111,7 +99,7 @@ public function dump(Data $data, $output = null) */ protected function getDumpHeader() { - $this->headerIsDumped = true; + $this->headerIsDumped = null !== $this->outputStream ? $this->outputStream : $this->lineDumper; if (null !== $this->dumpHeader) { return $this->dumpHeader; @@ -433,7 +421,7 @@ protected function dumpLine($depth, $endOfValue = false) if (-1 === $this->lastDepth) { $this->line = sprintf($this->dumpPrefix, $this->dumpId, $this->indentPad).$this->line; } - if (!$this->headerIsDumped) { + if ($this->headerIsDumped !== (null !== $this->outputStream ? $this->outputStream : $this->lineDumper)) { $this->line = $this->getDumpHeader().$this->line; } diff --git a/src/Symfony/Component/VarDumper/Tests/HtmlDumperTest.php b/src/Symfony/Component/VarDumper/Tests/HtmlDumperTest.php index 1171bb80831c..30495f7c4058 100644 --- a/src/Symfony/Component/VarDumper/Tests/HtmlDumperTest.php +++ b/src/Symfony/Component/VarDumper/Tests/HtmlDumperTest.php @@ -132,8 +132,7 @@ public function testCharset() $data = $cloner->cloneVar($var); $out = fopen('php://memory', 'r+b'); $dumper->dump($data, $out); - rewind($out); - $out = stream_get_contents($out); + $out = stream_get_contents($out, -1, 0); $this->assertStringMatchesFormat( <<setDumpHeader(''); + $dumper->setDumpBoundaries('', ''); + $cloner = new VarCloner(); + + $dumper->dump($cloner->cloneVar(123), $out); + $dumper->dump($cloner->cloneVar(456), $out); + + $out = stream_get_contents($out, -1, 0); + + $this->assertSame(<<<'EOTXT' +123 + +456 + + +EOTXT + , $out ); }