PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.8.3
Kubio AI Page Builder v2.8.3
2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / vendor / symfony / var-dumper / Command / ServerDumpCommand.php
kubio / vendor / symfony / var-dumper / Command Last commit date
Descriptor 1 year ago ServerDumpCommand.php 1 year ago
ServerDumpCommand.php
115 lines
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\VarDumper\Command;
13
14 use Symfony\Component\Console\Command\Command;
15 use Symfony\Component\Console\Completion\CompletionInput;
16 use Symfony\Component\Console\Completion\CompletionSuggestions;
17 use Symfony\Component\Console\Exception\InvalidArgumentException;
18 use Symfony\Component\Console\Input\InputInterface;
19 use Symfony\Component\Console\Input\InputOption;
20 use Symfony\Component\Console\Output\OutputInterface;
21 use Symfony\Component\Console\Style\SymfonyStyle;
22 use Symfony\Component\VarDumper\Cloner\Data;
23 use Symfony\Component\VarDumper\Command\Descriptor\CliDescriptor;
24 use Symfony\Component\VarDumper\Command\Descriptor\DumpDescriptorInterface;
25 use Symfony\Component\VarDumper\Command\Descriptor\HtmlDescriptor;
26 use Symfony\Component\VarDumper\Dumper\CliDumper;
27 use Symfony\Component\VarDumper\Dumper\HtmlDumper;
28 use Symfony\Component\VarDumper\Server\DumpServer;
29
30 /**
31 * Starts a dump server to collect and output dumps on a single place with multiple formats support.
32 *
33 * @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
34 *
35 * @final
36 */
37 class ServerDumpCommand extends Command
38 {
39 protected static $defaultName = 'server:dump';
40 protected static $defaultDescription = 'Start a dump server that collects and displays dumps in a single place';
41
42 private $server;
43
44 /** @var DumpDescriptorInterface[] */
45 private $descriptors;
46
47 public function __construct(DumpServer $server, array $descriptors = [])
48 {
49 $this->server = $server;
50 $this->descriptors = $descriptors + [
51 'cli' => new CliDescriptor(new CliDumper()),
52 'html' => new HtmlDescriptor(new HtmlDumper()),
53 ];
54
55 parent::__construct();
56 }
57
58 protected function configure()
59 {
60 $this
61 ->addOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format (%s)', implode(', ', $this->getAvailableFormats())), 'cli')
62 ->setDescription(self::$defaultDescription)
63 ->setHelp(<<<'EOF'
64 <info>%command.name%</info> starts a dump server that collects and displays
65 dumps in a single place for debugging you application:
66
67 <info>php %command.full_name%</info>
68
69 You can consult dumped data in HTML format in your browser by providing the <comment>--format=html</comment> option
70 and redirecting the output to a file:
71
72 <info>php %command.full_name% --format="html" > dump.html</info>
73
74 EOF
75 )
76 ;
77 }
78
79 protected function execute(InputInterface $input, OutputInterface $output): int
80 {
81 $io = new SymfonyStyle($input, $output);
82 $format = $input->getOption('format');
83
84 if (!$descriptor = $this->descriptors[$format] ?? null) {
85 throw new InvalidArgumentException(sprintf('Unsupported format "%s".', $format));
86 }
87
88 $errorIo = $io->getErrorStyle();
89 $errorIo->title('Symfony Var Dumper Server');
90
91 $this->server->start();
92
93 $errorIo->success(sprintf('Server listening on %s', $this->server->getHost()));
94 $errorIo->comment('Quit the server with CONTROL-C.');
95
96 $this->server->listen(function (Data $data, array $context, int $clientId) use ($descriptor, $io) {
97 $descriptor->describe($io, $data, $context, $clientId);
98 });
99
100 return 0;
101 }
102
103 public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
104 {
105 if ($input->mustSuggestOptionValuesFor('format')) {
106 $suggestions->suggestValues($this->getAvailableFormats());
107 }
108 }
109
110 private function getAvailableFormats(): array
111 {
112 return array_keys($this->descriptors);
113 }
114 }
115