diff --git a/src/Whoops/Handler/PrettyPageHandler.php b/src/Whoops/Handler/PrettyPageHandler.php index 2e838ac7..b2df5c1b 100644 --- a/src/Whoops/Handler/PrettyPageHandler.php +++ b/src/Whoops/Handler/PrettyPageHandler.php @@ -8,6 +8,8 @@ use InvalidArgumentException; use RuntimeException; +use Symfony\Component\VarDumper\Cloner\AbstractCloner; +use Symfony\Component\VarDumper\Cloner\VarCloner; use UnexpectedValueException; use Whoops\Exception\Formatter; use Whoops\Util\Misc; @@ -117,6 +119,23 @@ public function handle() // @todo: Make this more dynamic $helper = new TemplateHelper(); + $cloner = new VarCloner(); + // Only dump object internals if a custom caster exists. + $cloner->addCasters(['*' => function ($obj, $a, $stub, $isNested, $filter = 0) { + $class = $stub->class; + $classes = [$class => $class] + class_parents($class) + class_implements($class); + + foreach ($classes as $class) { + if (isset(AbstractCloner::$defaultCasters[$class])) { + return $a; + } + } + + // Remove all internals + return []; + }]); + $helper->setCloner($cloner); + $templateFile = $this->getResource("views/layout.html.php"); $cssFile = $this->getResource("css/whoops.base.css"); $zeptoFile = $this->getResource("js/zepto.min.js"); diff --git a/src/Whoops/Util/TemplateHelper.php b/src/Whoops/Util/TemplateHelper.php index 0b0d07ff..7df1307c 100644 --- a/src/Whoops/Util/TemplateHelper.php +++ b/src/Whoops/Util/TemplateHelper.php @@ -6,6 +6,8 @@ namespace Whoops\Util; +use Symfony\Component\VarDumper\Caster\Caster; +use Symfony\Component\VarDumper\Cloner\AbstractCloner; use Symfony\Component\VarDumper\Cloner\VarCloner; use Symfony\Component\VarDumper\Dumper\HtmlDumper; use Whoops\Exception\Frame; @@ -31,6 +33,11 @@ class TemplateHelper */ private $htmlDumperOutput; + /** + * @var AbstractCloner + */ + private $cloner; + /** * Escapes a string for output in an HTML document * @@ -110,10 +117,12 @@ public function dump($value) $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); + // exclude verbose information (e.g. exception stack traces) + $dumper->dump( + $this->getCloner()->cloneVar($value, Caster::EXCLUDE_VERBOSE), + $this->htmlDumperOutput + ); $output = $this->htmlDumperOutput->getOutput(); $this->htmlDumperOutput->clear(); @@ -244,4 +253,27 @@ public function getVariables() { 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; + } }