Skip to content

Commit

Permalink
Merge pull request #404 from jonasdt/remove-internals
Browse files Browse the repository at this point in the history
Don't dump object internals
  • Loading branch information
denis-sokolov committed Apr 5, 2016
2 parents 2cc2533 + 78d170f commit afab26b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/Whoops/Handler/PrettyPageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
38 changes: 35 additions & 3 deletions src/Whoops/Util/TemplateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +33,11 @@ class TemplateHelper
*/
private $htmlDumperOutput;

/**
* @var AbstractCloner
*/
private $cloner;

/**
* Escapes a string for output in an HTML document
*
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
}

0 comments on commit afab26b

Please sign in to comment.