1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Debug\Collector; |
6
|
|
|
|
7
|
|
|
use Symfony\Component\Console\Event\ConsoleCommandEvent; |
8
|
|
|
use Symfony\Component\Console\Event\ConsoleErrorEvent; |
9
|
|
|
use Symfony\Component\Console\Event\ConsoleTerminateEvent; |
10
|
|
|
|
11
|
|
|
final class CommandCollector implements CollectorInterface, IndexCollectorInterface |
12
|
|
|
{ |
13
|
|
|
use CollectorTrait; |
14
|
|
|
|
15
|
|
|
private array $commands = []; |
16
|
|
|
|
17
|
2 |
|
public function getCollected(): array |
18
|
|
|
{ |
19
|
2 |
|
return $this->commands; |
20
|
|
|
} |
21
|
|
|
|
22
|
2 |
|
public function collect(object $event): void |
23
|
|
|
{ |
24
|
2 |
|
if (!is_object($event) || !$this->isActive()) { |
25
|
1 |
|
return; |
26
|
|
|
} |
27
|
|
|
|
28
|
1 |
|
if ($event instanceof ConsoleCommandEvent) { |
29
|
1 |
|
$this->commands[get_class($event)] = [ |
30
|
1 |
|
'command' => $event->getCommand(), |
31
|
1 |
|
'input' => $event->getInput()->__toString(), |
|
|
|
|
32
|
1 |
|
'output' => $event->getOutput()->fetch(), |
|
|
|
|
33
|
|
|
]; |
34
|
|
|
} |
35
|
1 |
|
if ($event instanceof ConsoleErrorEvent) { |
36
|
1 |
|
$this->commands[get_class($event)] = [ |
37
|
1 |
|
'command' => $event->getCommand(), |
38
|
1 |
|
'input' => $event->getInput()->__toString(), |
39
|
1 |
|
'output' => $event->getOutput()->fetch(), |
40
|
1 |
|
'error' => $event->getError()->getMessage(), |
41
|
1 |
|
'exitCode' => $event->getExitCode(), |
42
|
|
|
]; |
43
|
|
|
} |
44
|
1 |
|
if ($event instanceof ConsoleTerminateEvent) { |
45
|
1 |
|
$this->commands[get_class($event)] = [ |
46
|
1 |
|
'command' => $event->getCommand(), |
47
|
1 |
|
'input' => $event->getInput()->__toString(), |
48
|
1 |
|
'output' => $event->getOutput()->fetch(), |
49
|
1 |
|
'exitCode' => $event->getExitCode(), |
50
|
|
|
]; |
51
|
|
|
} |
52
|
1 |
|
} |
53
|
|
|
|
54
|
1 |
|
public function getIndexData(): array |
55
|
|
|
{ |
56
|
1 |
|
$command = $this->commands[ConsoleCommandEvent::class]; |
57
|
|
|
return [ |
58
|
1 |
|
'command' => $command['input'], |
59
|
1 |
|
'commandClass' => get_class($command['command']), |
60
|
|
|
]; |
61
|
|
|
} |
62
|
|
|
|
63
|
1 |
|
private function reset(): void |
|
|
|
|
64
|
|
|
{ |
65
|
1 |
|
$this->commands = []; |
66
|
1 |
|
} |
67
|
|
|
} |
68
|
|
|
|