|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Gacela\Console\Infrastructure\Command; |
|
6
|
|
|
|
|
7
|
|
|
use Gacela\Console\ConsoleFacade; |
|
8
|
|
|
use Gacela\Console\Domain\AllAppModules\AppModule; |
|
9
|
|
|
use Gacela\Framework\DocBlockResolverAwareTrait; |
|
10
|
|
|
use Symfony\Component\Console\Command\Command; |
|
11
|
|
|
use Symfony\Component\Console\Helper\Table; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
13
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
14
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
15
|
|
|
use Symfony\Component\Console\Output\ConsoleOutput; |
|
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @method ConsoleFacade getFacade() |
|
20
|
|
|
*/ |
|
21
|
|
|
final class ListModulesCommand extends Command |
|
22
|
|
|
{ |
|
23
|
|
|
use DocBlockResolverAwareTrait; |
|
24
|
|
|
|
|
25
|
|
|
private const CHECK_SYMBOL = '✔️'; |
|
26
|
|
|
private const CROSS_SYMBOL = '✖️'; |
|
27
|
|
|
|
|
28
|
|
|
private ?OutputInterface $output = null; |
|
29
|
|
|
|
|
30
|
6 |
|
protected function configure(): void |
|
31
|
|
|
{ |
|
32
|
6 |
|
$this->setName('list:modules') |
|
33
|
6 |
|
->setDescription('Render all modules found') |
|
34
|
6 |
|
->addArgument('filter', InputArgument::OPTIONAL, 'Any filter to simplify the output') |
|
35
|
6 |
|
->addOption('detailed', 'd', InputOption::VALUE_NONE, 'Display all the modules in detail'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
4 |
|
protected function execute(InputInterface $input, OutputInterface $output): int |
|
39
|
|
|
{ |
|
40
|
4 |
|
$this->output = $output; |
|
41
|
|
|
|
|
42
|
4 |
|
$filter = (string)$input->getArgument('filter'); |
|
43
|
|
|
|
|
44
|
4 |
|
$this->generateListOfModules( |
|
45
|
4 |
|
(bool)$input->getOption('detailed'), |
|
46
|
4 |
|
$this->getFacade()->findAllAppModules($filter), |
|
47
|
4 |
|
); |
|
48
|
|
|
|
|
49
|
4 |
|
return self::SUCCESS; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
4 |
|
private function output(): OutputInterface |
|
53
|
|
|
{ |
|
54
|
4 |
|
return $this->output ?? new ConsoleOutput(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param list<AppModule> $modules |
|
59
|
|
|
*/ |
|
60
|
4 |
|
private function generateListOfModules(bool $isDetailed, array $modules): void |
|
61
|
|
|
{ |
|
62
|
4 |
|
if ($isDetailed) { |
|
63
|
1 |
|
$this->generateDetailedView($modules); |
|
64
|
|
|
} else { |
|
65
|
3 |
|
$this->generateSimpleView($modules); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @param list<AppModule> $modules |
|
71
|
|
|
*/ |
|
72
|
1 |
|
private function generateDetailedView(array $modules): void |
|
73
|
|
|
{ |
|
74
|
1 |
|
$result = ''; |
|
75
|
1 |
|
foreach ($modules as $i => $module) { |
|
76
|
1 |
|
$n = $i + 1; |
|
77
|
1 |
|
$factory = $module->factoryClass() ?? self::CROSS_SYMBOL; |
|
78
|
1 |
|
$config = $module->configClass() ?? self::CROSS_SYMBOL; |
|
79
|
1 |
|
$dependencyProviderClass = $module->dependencyProviderClass() ?? self::CROSS_SYMBOL; |
|
80
|
|
|
|
|
81
|
1 |
|
$result .= <<<TXT |
|
82
|
1 |
|
============================ |
|
83
|
1 |
|
{$n}.- <fg=green>{$module->moduleName()}</> |
|
84
|
|
|
---------------------------- |
|
85
|
1 |
|
<fg=cyan>Facade</>: {$module->facadeClass()} |
|
86
|
1 |
|
<fg=cyan>Factory</>: {$factory} |
|
87
|
1 |
|
<fg=cyan>Config</>: {$config} |
|
88
|
1 |
|
<fg=cyan>DependencyProvider</>: {$dependencyProviderClass} |
|
89
|
|
|
|
|
90
|
1 |
|
TXT; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
1 |
|
$this->output()->write($result); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @param list<AppModule> $modules |
|
98
|
|
|
*/ |
|
99
|
3 |
|
private function generateSimpleView(array $modules): void |
|
100
|
|
|
{ |
|
101
|
3 |
|
$rows = []; |
|
102
|
|
|
|
|
103
|
3 |
|
foreach ($modules as $module) { |
|
104
|
3 |
|
$rows[] = [ |
|
105
|
3 |
|
$module->fullModuleName(), |
|
106
|
3 |
|
self::CHECK_SYMBOL, // facade is always true |
|
107
|
3 |
|
$module->factoryClass() ? self::CHECK_SYMBOL : self::CROSS_SYMBOL, |
|
108
|
3 |
|
$module->configClass() ? self::CHECK_SYMBOL : self::CROSS_SYMBOL, |
|
109
|
3 |
|
$module->dependencyProviderClass() ? self::CHECK_SYMBOL : self::CROSS_SYMBOL, |
|
110
|
3 |
|
]; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
3 |
|
$table = new Table($this->output()); |
|
114
|
3 |
|
$table->setStyle('box'); |
|
115
|
3 |
|
$table->setHeaders(['Module namespace', 'Facade', 'Factory', 'Config', 'Dep. Provider']); |
|
116
|
3 |
|
$table->setRows($rows); |
|
117
|
3 |
|
$table->render(); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|