Skip to content

Commit

Permalink
Support custom Dumper instance e.g. to allow custom VarCloner etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
bezhermoso committed Oct 21, 2020
1 parent 755ea59 commit 0bac2d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/DumpServerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ public function register()
'source' => new SourceContextProvider('utf-8', base_path()),
]);

VarDumper::setHandler(function ($var) use ($connection) {
(new Dumper($connection))->dump($var);
$this->app->when(Dumper::class)->needs('$connection')->give($connection);
$app = $this->app;

VarDumper::setHandler(function ($var) use ($app) {
$app->make(Dumper::class)->dump($var);
});
}
}
10 changes: 9 additions & 1 deletion src/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(Connection $connection = null)
public function dump($value)
{
if (class_exists(CliDumper::class)) {
$data = (new VarCloner)->cloneVar($value);
$data = $this->createVarCloner()->cloneVar($value);

if ($this->connection === null || $this->connection->write($data) === false) {
$dumper = in_array(PHP_SAPI, ['cli', 'phpdbg']) ? new CliDumper : new HtmlDumper;
Expand All @@ -46,4 +46,12 @@ public function dump($value)
var_dump($value);
}
}

/**
* @return VarCloner
*/
protected function createVarCloner(): VarCloner
{
return new VarCloner();
}
}

0 comments on commit 0bac2d2

Please sign in to comment.