Skip to content
This repository was archived by the owner on Apr 21, 2023. It is now read-only.

Commit 85e7f76

Browse files
fixes
1 parent 994143e commit 85e7f76

2 files changed

Lines changed: 17 additions & 21 deletions

File tree

src/Symfony/Bridge/Twig/Extension/DumpExtension.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
*/
2323
class DumpExtension extends \Twig_Extension
2424
{
25-
public function __construct(ClonerInterface $cloner = null)
25+
private $cloner;
26+
27+
public function __construct(ClonerInterface $cloner)
2628
{
2729
$this->cloner = $cloner;
2830
}
@@ -46,7 +48,7 @@ public function getName()
4648

4749
public function dump(\Twig_Environment $env, $context)
4850
{
49-
if (!$env->isDebug() || !$this->cloner) {
51+
if (!$env->isDebug()) {
5052
return;
5153
}
5254

@@ -64,17 +66,14 @@ public function dump(\Twig_Environment $env, $context)
6466
unset($vars[0], $vars[1]);
6567
}
6668

67-
$html = '';
68-
$dumper = new HtmlDumper(function ($line, $depth) use (&$html) {
69-
if (-1 !== $depth) {
70-
$html .= str_repeat(' ', $depth).$line."\n";
71-
}
72-
});
69+
$dump = fopen('php://memory', 'r+b');
70+
$dumper = new HtmlDumper($dump);
7371

7472
foreach ($vars as $value) {
7573
$dumper->dump($this->cloner->cloneVar($value));
7674
}
75+
rewind($dump);
7776

78-
return $html;
77+
return stream_get_contents($dump);
7978
}
8079
}

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
3434

3535
public function __construct(Stopwatch $stopwatch = null, $fileLinkFormat = null)
3636
{
37-
$this->data = array();
37+
$this->data || $this->data = array();
3838
$this->stopwatch = $stopwatch;
3939
$this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
4040

@@ -156,24 +156,21 @@ public function getDumpsCount()
156156

157157
public function getDumps($format, $maxDepthLimit = -1, $maxItemsPerDepth = -1)
158158
{
159+
$data = fopen('php://memory', 'r+b');
160+
159161
if ('html' === $format) {
160-
$dumper = new HtmlDumper();
162+
$dumper = new HtmlDumper($data);
161163
} else {
162164
throw new \InvalidArgumentException(sprintf('Invalid dump format: %s', $format));
163165
}
164166
$dumps = array();
165167

166168
foreach ($this->data as $dump) {
167-
$data = '';
168-
$dumper->dump(
169-
$dump['data']->getLimitedClone($maxDepthLimit, $maxItemsPerDepth),
170-
function ($line, $depth) use (&$data) {
171-
if (-1 !== $depth) {
172-
$data .= str_repeat(' ', $depth).$line."\n";
173-
}
174-
}
175-
);
176-
$dump['data'] = $data;
169+
$dumper->dump($dump['data']->getLimitedClone($maxDepthLimit, $maxItemsPerDepth));
170+
rewind($data);
171+
$dump['data'] = stream_get_contents($data);
172+
ftruncate($data, 0);
173+
rewind($data);
177174
$dumps[] = $dump;
178175
}
179176

0 commit comments

Comments
 (0)