Skip to content

Commit 775f5fe

Browse files
authored
Merge pull request #6 from paulredmond/patch-1
Support HTML Output
2 parents e1e7f8f + 3310624 commit 775f5fe

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ Start the dump server by calling the artisan command:
3535
php artisan dump-server
3636
```
3737

38+
You can set the output format to HTML using the `--format` option:
39+
40+
```bash
41+
php artisan dump-server --format=html > dump.html
42+
```
43+
3844
And then you can, as you are used to, put `dump` calls in your methods. But instead of dumping the output in your current HTTP request, they will be dumped in the artisan command.
3945
This is very useful, when you want to dump data from API requests, without having to deal with HTTP errors.
4046

src/DumpServerCommand.php

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
use Illuminate\Console\Command;
66

7+
use InvalidArgumentException;
8+
use Illuminate\Support\Debug\HtmlDumper;
9+
use Symfony\Component\Console\Style\SymfonyStyle;
710
use Symfony\Component\VarDumper\Cloner\Data;
11+
use Symfony\Component\VarDumper\Command\Descriptor\HtmlDescriptor;
812
use Symfony\Component\VarDumper\Dumper\CliDumper;
913
use Symfony\Component\VarDumper\Server\DumpServer;
1014
use Symfony\Component\VarDumper\Command\Descriptor\CliDescriptor;
@@ -16,7 +20,8 @@ class DumpServerCommand extends Command
1620
*
1721
* @var string
1822
*/
19-
protected $signature = 'dump-server';
23+
protected $signature = 'dump-server {--format=cli : The output format (cli,html)}';
24+
2025
/**
2126
* The console command description.
2227
*
@@ -27,26 +32,42 @@ class DumpServerCommand extends Command
2732
/** @var DumpServer */
2833
private $server;
2934

35+
/**
36+
* @var \Symfony\Component\VarDumper\Command\Descriptor\DumpDescriptorInterface[]
37+
*/
38+
private $descriptors;
39+
3040
public function __construct(DumpServer $server)
3141
{
3242
$this->server = $server;
3343

44+
$this->descriptors = [
45+
'cli' => new CliDescriptor(new CliDumper()),
46+
'html' => new HtmlDescriptor(new HtmlDumper()),
47+
];
48+
3449
parent::__construct();
3550
}
3651

3752
public function handle()
3853
{
39-
$descriptor = new CliDescriptor(new CliDumper());
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');
4063

4164
$this->server->start();
4265

43-
$this->output->title('Laravel Var Dump Server');
44-
$this->output->success(sprintf('Server listening on %s', $this->server->getHost()));
45-
$this->output->comment('Quit the server with CONTROL-C.');
66+
$errorIo->success(sprintf('Server listening on %s', $this->server->getHost()));
67+
$errorIo->comment('Quit the server with CONTROL-C.');
4668

47-
$this->server->listen(function (Data $data, array $context, int $clientId) use ($descriptor) {
48-
$descriptor->describe($this->output, $data, $context, $clientId);
69+
$this->server->listen(function (Data $data, array $context, int $clientId) use ($descriptor, $io) {
70+
$descriptor->describe($io, $data, $context, $clientId);
4971
});
5072
}
51-
52-
}
73+
}

0 commit comments

Comments
 (0)