|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SimpleDIC\Console; |
|
4
|
|
|
|
|
5
|
|
|
use SimpleDIC\DIC; |
|
6
|
|
|
use Symfony\Component\Console\Command\Command; |
|
7
|
|
|
use Symfony\Component\Console\Helper\Table; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
11
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
12
|
|
|
|
|
13
|
|
|
class DebugCommand extends Command |
|
14
|
|
|
{ |
|
15
|
|
|
protected function configure() |
|
16
|
|
|
{ |
|
17
|
|
|
$this |
|
18
|
|
|
->setName('dic:debug') |
|
19
|
|
|
->setDescription('Dumps the entry list in the DIC.') |
|
20
|
|
|
->setHelp('This command shows you to complete entry list in the DIC from a valid config array.') |
|
21
|
|
|
->addArgument('config_file', InputArgument::REQUIRED) |
|
22
|
|
|
; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
26
|
|
|
{ |
|
27
|
|
|
$configFile = $input->getArgument('config_file'); |
|
28
|
|
|
|
|
29
|
|
|
if (false === file_exists($configFile)) { |
|
|
|
|
|
|
30
|
|
|
throw new \InvalidArgumentException($configFile . ' is not a valid file'); |
|
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
DIC::initFromFile($configFile); |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
$keys = DIC::keys(); |
|
36
|
|
|
asort($keys); |
|
37
|
|
|
|
|
38
|
|
|
$table = new Table($output); |
|
39
|
|
|
$table->setHeaders(['#', 'Alias', 'Content']); |
|
40
|
|
|
|
|
41
|
|
|
$i = 1; |
|
42
|
|
|
foreach ($keys as $key) { |
|
43
|
|
|
$table->setRow($i, [$i, $key, $this->getValue($key)]); |
|
44
|
|
|
$i++; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$table->render(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param string $key |
|
52
|
|
|
* |
|
53
|
|
|
* @return mixed|string |
|
54
|
|
|
*/ |
|
55
|
|
|
private function getValue($key) |
|
56
|
|
|
{ |
|
57
|
|
|
$dicKey = DIC::get($key); |
|
58
|
|
|
|
|
59
|
|
|
if (false === $dicKey) { |
|
60
|
|
|
return '<fg=red>Invalid Entry</>'; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
if (is_object($dicKey)) { |
|
64
|
|
|
return '<fg=cyan>' . get_class($dicKey) . '</>'; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
if (is_array($dicKey)) { |
|
68
|
|
|
return '<fg=green>' . implode("|", $dicKey) . '</>'; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return '<fg=yellow>' . $dicKey . '</>'; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|