| 148 |
lars |
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\Descriptor;
|
|
|
13 |
|
|
|
14 |
use Symfony\Component\Console\Input\ArrayInput;
|
|
|
15 |
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
16 |
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
|
17 |
use Symfony\Component\VarDumper\Cloner\Data;
|
|
|
18 |
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
|
|
19 |
|
|
|
20 |
/**
|
|
|
21 |
* Describe collected data clones for cli output.
|
|
|
22 |
*
|
|
|
23 |
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
|
|
|
24 |
*
|
|
|
25 |
* @final
|
|
|
26 |
*/
|
|
|
27 |
class CliDescriptor implements DumpDescriptorInterface
|
|
|
28 |
{
|
|
|
29 |
private CliDumper $dumper;
|
|
|
30 |
private mixed $lastIdentifier = null;
|
|
|
31 |
|
|
|
32 |
public function __construct(CliDumper $dumper)
|
|
|
33 |
{
|
|
|
34 |
$this->dumper = $dumper;
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
public function describe(OutputInterface $output, Data $data, array $context, int $clientId): void
|
|
|
38 |
{
|
|
|
39 |
$io = $output instanceof SymfonyStyle ? $output : new SymfonyStyle(new ArrayInput([]), $output);
|
|
|
40 |
$this->dumper->setColors($output->isDecorated());
|
|
|
41 |
|
|
|
42 |
$rows = [['date', date('r', (int) $context['timestamp'])]];
|
|
|
43 |
$lastIdentifier = $this->lastIdentifier;
|
|
|
44 |
$this->lastIdentifier = $clientId;
|
|
|
45 |
|
|
|
46 |
$section = "Received from client #$clientId";
|
|
|
47 |
if (isset($context['request'])) {
|
|
|
48 |
$request = $context['request'];
|
|
|
49 |
$this->lastIdentifier = $request['identifier'];
|
|
|
50 |
$section = sprintf('%s %s', $request['method'], $request['uri']);
|
|
|
51 |
if ($controller = $request['controller']) {
|
|
|
52 |
$rows[] = ['controller', rtrim($this->dumper->dump($controller, true), "\n")];
|
|
|
53 |
}
|
|
|
54 |
} elseif (isset($context['cli'])) {
|
|
|
55 |
$this->lastIdentifier = $context['cli']['identifier'];
|
|
|
56 |
$section = '$ '.$context['cli']['command_line'];
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
if ($this->lastIdentifier !== $lastIdentifier) {
|
|
|
60 |
$io->section($section);
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
if (isset($context['source'])) {
|
|
|
64 |
$source = $context['source'];
|
|
|
65 |
$sourceInfo = sprintf('%s on line %d', $source['name'], $source['line']);
|
|
|
66 |
if ($fileLink = $source['file_link'] ?? null) {
|
|
|
67 |
$sourceInfo = sprintf('<href=%s>%s</>', $fileLink, $sourceInfo);
|
|
|
68 |
}
|
|
|
69 |
$rows[] = ['source', $sourceInfo];
|
|
|
70 |
$file = $source['file_relative'] ?? $source['file'];
|
|
|
71 |
$rows[] = ['file', $file];
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
$io->table([], $rows);
|
|
|
75 |
|
|
|
76 |
$this->dumper->dump($data);
|
|
|
77 |
$io->newLine();
|
|
|
78 |
}
|
|
|
79 |
}
|