Allow to set the cloner

This commit is contained in:
Jonas De Taeye
2016-03-20 14:38:42 +01:00
parent a9d17d13ac
commit 9278a21fac
+33 -3
View File
@@ -6,6 +6,7 @@
namespace Whoops\Util;
use Symfony\Component\VarDumper\Cloner\AbstractCloner;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
use Whoops\Exception\Frame;
@@ -31,6 +32,11 @@ class TemplateHelper
*/
private $htmlDumperOutput;
/**
* @var AbstractCloner
*/
private $cloner;
/**
* Escapes a string for output in an HTML document
*
@@ -110,10 +116,11 @@ class TemplateHelper
$dumper = $this->getDumper();
if ($dumper) {
$cloner = new VarCloner();
// re-use the same DumpOutput instance, so it won't re-render the global styles/scripts on each dump.
$dumper->dump($cloner->cloneVar($value), $this->htmlDumperOutput);
$dumper->dump(
$this->getCloner()->cloneVar($value),
$this->htmlDumperOutput
);
$output = $this->htmlDumperOutput->getOutput();
$this->htmlDumperOutput->clear();
@@ -244,4 +251,27 @@ class TemplateHelper
{
return $this->variables;
}
/**
* Set the cloner used for dumping variables.
*
* @param AbstractCloner $cloner
*/
public function setCloner($cloner)
{
$this->cloner = $cloner;
}
/**
* Get the cloner used for dumping variables.
*
* @return AbstractCloner
*/
public function getCloner()
{
if (!$this->cloner) {
$this->cloner = new VarCloner();
}
return $this->cloner;
}
}