1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Darkilliant\ProcessBundle\Command; |
6
|
|
|
|
7
|
|
|
use Darkilliant\ProcessBundle\DependencyInjection\DarkilliantProcessExtension; |
8
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
9
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
12
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
13
|
|
|
use Darkilliant\ProcessBundle\Logger\InMemoryLogger; |
14
|
|
|
use Darkilliant\ProcessBundle\Runner\StepDescripterRunner; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @internal |
18
|
|
|
* Class DebugProcessCommand |
19
|
|
|
* |
20
|
|
|
* @codeCoverageIgnore |
21
|
|
|
*/ |
22
|
|
|
class DebugProcessCommand extends ContainerAwareCommand |
23
|
|
|
{ |
24
|
|
|
public function configure() |
25
|
|
|
{ |
26
|
|
|
$this->setName('debug:process') |
27
|
|
|
->addArgument('process', InputArgument::OPTIONAL); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function execute(InputInterface $input, OutputInterface $output) |
31
|
|
|
{ |
32
|
|
|
$outputHelper = new SymfonyStyle($input, $output); |
33
|
|
|
|
34
|
|
|
$config = $this->getContainer()->getParameter(DarkilliantProcessExtension::PARAMETER_NAME); |
35
|
|
|
|
36
|
|
|
if (!$input->getArgument('process')) { |
37
|
|
|
return $this->describeProcessList($config, $outputHelper); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
return $this->describeProcess( |
41
|
|
|
$input->getArgument('process'), |
42
|
|
|
$outputHelper |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param array $config |
48
|
|
|
* @param SymfonyStyle $outputHelper |
49
|
|
|
* |
50
|
|
|
* @throws \Exception |
51
|
|
|
*/ |
52
|
|
|
private function describeProcess(string $process, SymfonyStyle $outputHelper): int |
53
|
|
|
{ |
54
|
|
|
$outputHelper->section(sprintf('Describe %s', $process)); |
55
|
|
|
|
56
|
|
|
/** @var StepDescripterRunner $stepDescripter */ |
57
|
|
|
$stepDescripter = $this->getContainer()->get(StepDescripterRunner::class); |
58
|
|
|
/** @var InMemoryLogger $inMemoryLogger */ |
59
|
|
|
$inMemoryLogger = $this->getContainer()->get(InMemoryLogger::class); |
60
|
|
|
|
61
|
|
|
$stepDescripter->run($stepDescripter->buildConfigurationProcess($process)); |
62
|
|
|
|
63
|
|
|
$outputHelper->listing($inMemoryLogger->getMessages()); |
64
|
|
|
|
65
|
|
|
return 0; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
private function describeProcessList(array $config, SymfonyStyle $outputHelper): int |
69
|
|
|
{ |
70
|
|
|
$outputHelper->section('List of process'); |
71
|
|
|
|
72
|
|
|
$list = []; |
73
|
|
|
foreach ($config['process'] as $processName => $config) { |
74
|
|
|
$list[] = [$processName, implode(', ', $config['deprecated'])]; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$outputHelper->table( |
78
|
|
|
['class', 'deprecated'], |
79
|
|
|
$list |
80
|
|
|
); |
81
|
|
|
|
82
|
|
|
return 0; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|