1 | <?php |
||
2 | |||
3 | namespace BeyondCode\DumpServer; |
||
4 | |||
5 | use Symfony\Component\VarDumper\Cloner\VarCloner; |
||
6 | use Symfony\Component\VarDumper\Dumper\CliDumper; |
||
7 | use Symfony\Component\VarDumper\Dumper\HtmlDumper; |
||
8 | use Symfony\Component\VarDumper\Server\Connection; |
||
9 | |||
10 | class Dumper |
||
11 | { |
||
12 | /** |
||
13 | * The connection. |
||
14 | * |
||
15 | * @var \Symfony\Component\VarDumper\Server\Connection|null |
||
16 | */ |
||
17 | private $connection; |
||
18 | |||
19 | /** |
||
20 | * Dumper constructor. |
||
21 | * |
||
22 | * @param \Symfony\Component\VarDumper\Server\Connection|null $connection |
||
23 | * @return void |
||
24 | */ |
||
25 | public function __construct(Connection $connection = null) |
||
26 | { |
||
27 | $this->connection = $connection; |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * Dump a value with elegance. |
||
32 | * |
||
33 | * @param mixed $value |
||
34 | * @return void |
||
35 | */ |
||
36 | public function dump($value) |
||
37 | { |
||
38 | if (class_exists(CliDumper::class)) { |
||
39 | $data = $this->createVarCloner()->cloneVar($value); |
||
40 | |||
41 | if ($this->connection === null || $this->connection->write($data) === false) { |
||
42 | $dumper = in_array(PHP_SAPI, ['cli', 'phpdbg']) ? new CliDumper : new HtmlDumper; |
||
43 | $dumper->dump($data); |
||
44 | } |
||
45 | } else { |
||
46 | var_dump($value); |
||
0 ignored issues
–
show
Security
Debugging Code
introduced
by
![]() |
|||
47 | } |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @return VarCloner |
||
52 | */ |
||
53 | protected function createVarCloner(): VarCloner |
||
54 | { |
||
55 | return new VarCloner(); |
||
56 | } |
||
57 | } |
||
58 |