Skip to content

[WebProfilerBundle] Simplify WebProfilerExtension #20038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 2 additions & 29 deletions src/Symfony/Bundle/WebProfilerBundle/Twig/WebProfilerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class WebProfilerExtension extends \Twig_Extension_Profiler
class WebProfilerExtension extends \Twig_Extension
{
/**
* @var ValueExporter
Expand All @@ -32,32 +32,9 @@ class WebProfilerExtension extends \Twig_Extension_Profiler
*/
private $dumper;

/**
* @var resource
*/
private $output;

/**
* @var int
*/
private $stackLevel = 0;

public function __construct(HtmlDumper $dumper = null)
{
$this->dumper = $dumper ?: new HtmlDumper();
$this->dumper->setOutput($this->output = fopen('php://memory', 'r+b'));
}

public function enter(\Twig_Profiler_Profile $profile)
{
++$this->stackLevel;
}

public function leave(\Twig_Profiler_Profile $profile)
{
if (0 === --$this->stackLevel) {
$this->dumper->setOutput($this->output = fopen('php://memory', 'r+b'));
}
}

/**
Expand All @@ -78,14 +55,10 @@ public function getFunctions()
public function dumpData(\Twig_Environment $env, Data $data, $maxDepth = 0)
{
$this->dumper->setCharset($env->getCharset());
$this->dumper->dump($data, null, array(
$dump = $this->dumper->dump($data, true, array(
'maxDepth' => $maxDepth,
));

$dump = stream_get_contents($this->output, -1, 0);
rewind($this->output);
ftruncate($this->output, 0);

return str_replace("\n</pre", '</pre', rtrim($dump));
}

Expand Down