8000 bug #19623 [VarDumper] Fix dumping continuations (nicolas-grekas) · symfony/symfony@adb7033 · GitHub
[go: up one dir, main page]

Skip to content

Commit adb7033

Browse files
committed
bug #19623 [VarDumper] Fix dumping continuations (nicolas-grekas)
This PR was merged into the 2.7 branch. Discussion ---------- [VarDumper] Fix dumping continuations | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Dumping twice on the same destination shouldn't dump headers again. Commits ------- da96719 [VarDumper] Fix dumping continuations
2 parents d62ac4d + da96719 commit adb7033

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,7 @@ public function getDumps($format, $maxDepthLimit = -1, $maxItemsPerDepth = -1)
211211
// getLimitedClone is @deprecated, to be removed in 3.0
212212
$dumper->dump($dump['data']->getLimitedClone($maxDepthLimit, $maxItemsPerDepth));
213213
}
214-
rewind($data);
215-
$dump['data'] = stream_get_contents($data);
214+
$dump['data'] = stream_get_contents($data, -1, 0);
216215
ftruncate($data, 0);
217216
rewind($data);
218217
$dumps[] = $dump;

src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,6 @@ public function __construct($output = null, $charset = null)
5454
$this->dumpId = 'sf-dump-'.mt_rand();
5555
}
5656

57-
/**
58-
* {@inheritdoc}
59-
*/
60-
public function setOutput($output)
61-
{
62-
if ($output !== $prev = parent::setOutput($output)) {
63-
$this->headerIsDumped = false;
64-
}
65-
66-
return $prev;
67-
}
68-
6957
/**
7058
* {@inheritdoc}
7159
*/
@@ -111,7 +99,7 @@ public function dump(Data $data, $output = null)
11199
*/
112100
protected function getDumpHeader()
113101
{
114-
$this->headerIsDumped = true;
102+
$this->headerIsDumped = null !== $this->outputStream ? $this->outputStream : $this->lineDumper;
115103

116104
if (null !== $this->dumpHeader) {
117105
return $this->dumpHeader;
@@ -433,7 +421,7 @@ protected function dumpLine($depth, $endOfValue = false)
433421
if (-1 === $this->lastDepth) {
434422
$this->line = sprintf($this->dumpPrefix, $this->dumpId, $this->indentPad).$this->line;
435423
}
436-
if (!$this->headerIsDumped) {
424+
if ($this->headerIsDumped !== (null !== $this->outputStream ? $this->outputStream : $this->lineDumper)) {
437425
$this->line = $this->getDumpHeader().$this->line;
438426
}
439427

src/Symfony/Component/VarDumper/Tests/HtmlDumperTest.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ public function testCharset()
132132
$data = $cloner->cloneVar($var);
133133
$out = fopen('php://memory', 'r+b');
134134
$dumper->dump($data, $out);
135-
rewind($out);
136-
$out = stream_get_contents($out);
135+
$out = stream_get_contents($out, -1, 0);
137136

138137
$this->assertStringMatchesFormat(
139138
<<<EOTXT
@@ -142,7 +141,32 @@ public function testCharset()
142141
143142
EOTXT
144143
,
144+
$out
145+
);
146+
}
145147

148+
public function testAppend()
149+
{
150+
$out = fopen('php://memory', 'r+b');
151+
152+
$dumper = new HtmlDumper();
153+
$dumper->setDumpHeader('<foo></foo>');
154+
$dumper->setDumpBoundaries('<bar>', '</bar>');
155+
$cloner = new VarCloner();
156+
157+
$dumper->dump($cloner->cloneVar(123), $out);
158+
$dumper->dump($cloner->cloneVar(456), $out);
159+
160+
$out = stream_get_contents($out, -1, 0);
161+
162+
$this->assertSame(<<<'EOTXT'
163+
<foo></foo><bar><span class=sf-dump-num>123</span>
164+
</bar>
165+
<bar><span class=sf-dump-num>456</span>
166+
</bar>
167+
168+
EOTXT
169+
,
146170
$out
147171
);
148172
}

0 commit comments

Comments
 (0)
0