1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BeyondCode\DumpServer; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
|
7
|
|
|
use InvalidArgumentException; |
8
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
9
|
|
|
use Symfony\Component\VarDumper\Cloner\Data; |
10
|
|
|
use Symfony\Component\VarDumper\Command\Descriptor\HtmlDescriptor; |
11
|
|
|
use Symfony\Component\VarDumper\Dumper\CliDumper; |
12
|
|
|
use Symfony\Component\VarDumper\Dumper\HtmlDumper; |
13
|
|
|
use Symfony\Component\VarDumper\Server\DumpServer; |
14
|
|
|
use Symfony\Component\VarDumper\Command\Descriptor\CliDescriptor; |
15
|
|
|
|
16
|
|
|
class DumpServerCommand extends Command |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* The console command name. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $signature = 'dump-server {--format=cli : The output format (cli,html)}'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The console command description. |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $description = 'Start the dump server to collect dump information'; |
31
|
|
|
|
32
|
|
|
/** @var DumpServer */ |
33
|
|
|
private $server; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var \Symfony\Component\VarDumper\Command\Descriptor\DumpDescriptorInterface[] |
37
|
|
|
*/ |
38
|
|
|
private $descriptors; |
39
|
|
|
|
40
|
|
|
public function __construct(DumpServer $server) |
41
|
|
|
{ |
42
|
|
|
$this->server = $server; |
43
|
|
|
|
44
|
|
|
$this->descriptors = [ |
|
|
|
|
45
|
|
|
'cli' => new CliDescriptor(new CliDumper()), |
46
|
|
|
'html' => new HtmlDescriptor(new HtmlDumper()), |
47
|
|
|
]; |
48
|
|
|
|
49
|
|
|
parent::__construct(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function handle() |
53
|
|
|
{ |
54
|
|
|
$io = new SymfonyStyle($this->input, $this->output); |
55
|
|
|
$format = $this->option('format'); |
56
|
|
|
|
57
|
|
|
if (! $descriptor = $this->descriptors[$format] ?? null) { |
58
|
|
|
throw new InvalidArgumentException(sprintf('Unsupported format "%s".', $format)); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$errorIo = $io->getErrorStyle(); |
62
|
|
|
$errorIo->title('Laravel Var Dump Server'); |
63
|
|
|
|
64
|
|
|
$this->server->start(); |
65
|
|
|
|
66
|
|
|
$errorIo->success(sprintf('Server listening on %s', $this->server->getHost())); |
67
|
|
|
$errorIo->comment('Quit the server with CONTROL-C.'); |
68
|
|
|
|
69
|
|
|
$this->server->listen(function (Data $data, array $context, int $clientId) use ($descriptor, $io) { |
70
|
|
|
$descriptor->describe($io, $data, $context, $clientId); |
71
|
|
|
}); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..