1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Antidot\DevTools\Application\Command; |
6
|
|
|
|
7
|
|
|
use Symfony\Component\Console\Command\Command; |
8
|
|
|
use Symfony\Component\Console\Helper\Table; |
9
|
|
|
use Symfony\Component\Console\Helper\TableSeparator; |
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
12
|
|
|
|
13
|
|
|
final class ShowContainer extends Command |
14
|
|
|
{ |
15
|
|
|
public const NAME = 'config:show:container'; |
16
|
|
|
/** @var array<mixed> */ |
17
|
|
|
private array $config; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param array<mixed> $config |
21
|
|
|
*/ |
22
|
|
|
public function __construct(array $config) |
23
|
|
|
{ |
24
|
|
|
parent::__construct(); |
25
|
|
|
$this->config = $config; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
protected function configure(): void |
29
|
|
|
{ |
30
|
|
|
$this->setName(self::NAME) |
31
|
|
|
->setDescription('Show all available services inner container.'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): ?int |
35
|
|
|
{ |
36
|
|
|
$table = new Table($output); |
37
|
|
|
|
38
|
|
|
$table->setHeaders(['service', 'implementation']); |
39
|
|
|
$table->addRow(['<info>Services</info>']); |
40
|
|
|
$table->addRow(new TableSeparator()); |
41
|
|
|
$services = array_replace_recursive( |
42
|
|
|
$this->config['services'] ?? [], |
43
|
|
|
$this->config['dependencies']['invokables'] ?? [] |
44
|
|
|
); |
45
|
|
|
foreach ($services as $key => $service) { |
46
|
|
|
if (is_string($service)) { |
47
|
|
|
$table->addRow([$key, $service]); |
48
|
|
|
continue; |
49
|
|
|
} |
50
|
|
|
$table->addRow([$key, $service['class']]); |
51
|
|
|
foreach ($service['arguments'] ?? [] as $index => $argument) { |
52
|
|
|
$table->addRow([ |
53
|
|
|
'', |
54
|
|
|
' - '.$index.'::'.(\is_string($argument) ? $argument : \gettype($argument)), |
55
|
|
|
]); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
$table->addRow(new TableSeparator()); |
59
|
|
|
$table->addRow(['<info>Factories</info>']); |
60
|
|
|
$table->addRow(new TableSeparator()); |
61
|
|
|
$factories = array_replace_recursive( |
62
|
|
|
$this->config['factories'] ?? [], |
63
|
|
|
$this->config['dependencies']['factories'] ?? [] |
64
|
|
|
); |
65
|
|
|
foreach ($factories as $key => $factory) { |
66
|
|
|
if (is_callable($factory)) { |
67
|
|
|
$table->addRow([$key, 'Anonymous function']); |
68
|
|
|
continue; |
69
|
|
|
} |
70
|
|
|
$table->addRow([$key, is_array($factory) ? $factory[0].'::'.$factory[1] : $factory]); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$table->render(); |
74
|
|
|
return 0; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|