1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BeyondCode\DumpServer; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
|
7
|
|
|
use InvalidArgumentException; |
8
|
|
|
use Symfony\Component\VarDumper\Cloner\Data; |
9
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
10
|
|
|
use Symfony\Component\VarDumper\Dumper\CliDumper; |
11
|
|
|
use Symfony\Component\VarDumper\Dumper\HtmlDumper; |
12
|
|
|
use Symfony\Component\VarDumper\Server\DumpServer; |
13
|
|
|
use Symfony\Component\VarDumper\Command\Descriptor\CliDescriptor; |
14
|
|
|
use Symfony\Component\VarDumper\Command\Descriptor\HtmlDescriptor; |
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
|
|
|
/** |
33
|
|
|
* The Dump server. |
34
|
|
|
* |
35
|
|
|
* @var \Symfony\Component\VarDumper\Server\DumpServer |
36
|
|
|
*/ |
37
|
|
|
private $server; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* DumpServerCommand constructor. |
41
|
|
|
* |
42
|
|
|
* @param \Symfony\Component\VarDumper\Server\DumpServer $server |
43
|
|
|
* @return void |
|
|
|
|
44
|
|
|
*/ |
45
|
|
|
public function __construct(DumpServer $server) |
46
|
|
|
{ |
47
|
|
|
$this->server = $server; |
48
|
|
|
|
49
|
|
|
parent::__construct(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Handle the command. |
54
|
|
|
* |
55
|
|
|
* @return void |
56
|
|
|
*/ |
57
|
|
|
public function handle() |
58
|
|
|
{ |
59
|
|
|
switch ($format = $this->option('format')) { |
60
|
|
|
case 'cli': |
61
|
|
|
$descriptor = new CliDescriptor(new CliDumper); |
62
|
|
|
break; |
63
|
|
|
case 'html': |
64
|
|
|
$descriptor = new HtmlDescriptor(new HtmlDumper); |
65
|
|
|
break; |
66
|
|
|
default: |
67
|
|
|
throw new InvalidArgumentException(sprintf('Unsupported format "%s".', $format)); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$io = new SymfonyStyle($this->input, $this->output); |
71
|
|
|
|
72
|
|
|
$errorIo = $io->getErrorStyle(); |
73
|
|
|
$errorIo->title('Laravel Var Dump Server'); |
74
|
|
|
|
75
|
|
|
$this->server->start(); |
76
|
|
|
|
77
|
|
|
$errorIo->success(sprintf('Server listening on %s', $this->server->getHost())); |
78
|
|
|
$errorIo->comment('Quit the server with CONTROL-C.'); |
79
|
|
|
|
80
|
|
|
$this->server->listen(function (Data $data, array $context, int $clientId) use ($descriptor, $io) { |
81
|
|
|
$descriptor->describe($io, $data, $context, $clientId); |
82
|
|
|
$this->share($data, $context, $clientId); |
83
|
|
|
}); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Share the contents of the dump. |
88
|
|
|
* |
89
|
|
|
* @param \Symfony\Component\VarDumper\Cloner\Data $data |
90
|
|
|
* @param array $context |
91
|
|
|
* @param int $clientId |
92
|
|
|
* |
93
|
|
|
* @return void |
94
|
|
|
*/ |
95
|
|
|
protected function share(Data $data, array $context, int $clientId) |
|
|
|
|
96
|
|
|
{ |
97
|
|
|
// |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.