|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Facade\Ignition\DumpRecorder; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Foundation\Application; |
|
6
|
|
|
use Illuminate\Support\Arr; |
|
7
|
|
|
use Symfony\Component\VarDumper\Cloner\Data; |
|
8
|
|
|
use Symfony\Component\VarDumper\Cloner\VarCloner; |
|
9
|
|
|
use Symfony\Component\VarDumper\Dumper\CliDumper; |
|
10
|
|
|
use Symfony\Component\VarDumper\Dumper\HtmlDumper as BaseHtmlDumper; |
|
11
|
|
|
use Symfony\Component\VarDumper\VarDumper; |
|
12
|
|
|
|
|
13
|
|
|
class DumpRecorder |
|
14
|
|
|
{ |
|
15
|
|
|
protected $dumps = []; |
|
16
|
|
|
|
|
17
|
|
|
/** @var \Illuminate\Foundation\Application */ |
|
18
|
|
|
protected $app; |
|
19
|
|
|
|
|
20
|
|
|
public function __construct(Application $app) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->app = $app; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function register(): self |
|
26
|
|
|
{ |
|
27
|
|
|
$multiDumpHandler = new MultiDumpHandler(); |
|
28
|
|
|
|
|
29
|
|
|
$this->app->singleton(MultiDumpHandler::class, $multiDumpHandler); |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
$previousHandler = VarDumper::setHandler(function ($var) use ($multiDumpHandler) { |
|
32
|
|
|
$multiDumpHandler->dump($var); |
|
33
|
|
|
}); |
|
34
|
|
|
|
|
35
|
|
|
if ($previousHandler) { |
|
36
|
|
|
$multiDumpHandler->addHandler($previousHandler); |
|
37
|
|
|
} else { |
|
38
|
|
|
$multiDumpHandler->addHandler($this->getDefaultHandler()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$multiDumpHandler->addHandler(function ($var) { |
|
42
|
|
|
$this->app->make(DumpHandler::class)->dump($var); |
|
43
|
|
|
}); |
|
44
|
|
|
|
|
45
|
|
|
return $this; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function record(Data $data) |
|
49
|
|
|
{ |
|
50
|
|
|
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 7); |
|
51
|
|
|
$file = Arr::get($backtrace, '6.file'); |
|
52
|
|
|
$lineNumber = Arr::get($backtrace, '6.line'); |
|
53
|
|
|
|
|
54
|
|
|
$htmlDump = (new HtmlDumper())->dump($data); |
|
55
|
|
|
|
|
56
|
|
|
$this->dumps[] = new Dump($htmlDump, $file, $lineNumber); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function getDumps(): array |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->toArray(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function reset() |
|
65
|
|
|
{ |
|
66
|
|
|
$this->dumps = []; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function toArray(): array |
|
70
|
|
|
{ |
|
71
|
|
|
$dumps = []; |
|
72
|
|
|
|
|
73
|
|
|
foreach ($this->dumps as $dump) { |
|
74
|
|
|
$dumps[] = $dump->toArray(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return $dumps; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
protected function getDefaultHandler() |
|
81
|
|
|
{ |
|
82
|
|
|
return function ($value) { |
|
83
|
|
|
$data = (new VarCloner)->cloneVar($value); |
|
84
|
|
|
|
|
85
|
|
|
$dumper = in_array(PHP_SAPI, ['cli', 'phpdbg']) ? new CliDumper : new BaseHtmlDumper; |
|
86
|
|
|
$dumper->dump($data); |
|
87
|
|
|
}; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: