Skip to content

Commit 1d1b4c0

Browse files
authored
Merge pull request #70 from bezhermoso/custom-dumper
[Feature] Support custom BeyondCode\DumpServer\Dumper binding
2 parents 755ea59 + 0bac2d2 commit 1d1b4c0

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/DumpServerServiceProvider.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ public function register()
4949
'source' => new SourceContextProvider('utf-8', base_path()),
5050
]);
5151

52-
VarDumper::setHandler(function ($var) use ($connection) {
53-
(new Dumper($connection))->dump($var);
52+
$this->app->when(Dumper::class)->needs('$connection')->give($connection);
53+
$app = $this->app;
54+
55+
VarDumper::setHandler(function ($var) use ($app) {
56+
$app->make(Dumper::class)->dump($var);
5457
});
5558
}
5659
}

src/Dumper.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(Connection $connection = null)
3636
public function dump($value)
3737
{
3838
if (class_exists(CliDumper::class)) {
39-
$data = (new VarCloner)->cloneVar($value);
39+
$data = $this->createVarCloner()->cloneVar($value);
4040

4141
if ($this->connection === null || $this->connection->write($data) === false) {
4242
$dumper = in_array(PHP_SAPI, ['cli', 'phpdbg']) ? new CliDumper : new HtmlDumper;
@@ -46,4 +46,12 @@ public function dump($value)
4646
var_dump($value);
4747
}
4848
}
49+
50+
/**
51+
* @return VarCloner
52+
*/
53+
protected function createVarCloner(): VarCloner
54+
{
55+
return new VarCloner();
56+
}
4957
}

0 commit comments

Comments
 (0)