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
|
|
|
/** |
16
|
|
|
* DebugCommand constructor. |
17
|
|
|
* |
18
|
|
|
* @param string $filename |
19
|
|
|
* @param null $name |
|
|
|
|
20
|
|
|
* |
21
|
|
|
* @throws \SimpleDIC\Exceptions\ParserException |
22
|
|
|
*/ |
23
|
|
|
public function __construct($filename, $name = null) |
24
|
|
|
{ |
25
|
|
|
parent::__construct($name); |
26
|
|
|
|
27
|
|
|
DIC::initFromFile($filename); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
protected function configure() |
31
|
|
|
{ |
32
|
|
|
$this |
33
|
|
|
->setName('dic:debug') |
34
|
|
|
->setDescription('Dumps the entry list in the DIC.') |
35
|
|
|
->setHelp('This command shows you to complete entry list in the DIC from a valid config array.') |
36
|
|
|
; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
40
|
|
|
{ |
41
|
|
|
$keys = DIC::keys(); |
42
|
|
|
asort($keys); |
43
|
|
|
|
44
|
|
|
$table = new Table($output); |
45
|
|
|
$table->setHeaders(['#', 'Alias', 'Content']); |
46
|
|
|
|
47
|
|
|
$i = 1; |
48
|
|
|
foreach ($keys as $key) { |
49
|
|
|
$table->setRow($i, [$i, $key, $this->getValue($key)]); |
50
|
|
|
$i++; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$table->render(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string $key |
58
|
|
|
* |
59
|
|
|
* @return mixed|string |
60
|
|
|
*/ |
61
|
|
|
private function getValue($key) |
62
|
|
|
{ |
63
|
|
|
$dicKey = DIC::get($key); |
64
|
|
|
|
65
|
|
|
if (false === $dicKey) { |
66
|
|
|
return '<fg=red>Invalid Entry</>'; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if (is_object($dicKey)) { |
70
|
|
|
return '<fg=cyan>' . get_class($dicKey) . '</>'; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
if (is_array($dicKey)) { |
74
|
|
|
return '<fg=green>' . implode("|", $dicKey) . '</>'; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return '<fg=yellow>' . $dicKey . '</>'; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|