|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Magium\Configuration\Console\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Magium\Configuration\Config\Config; |
|
6
|
|
|
use Magium\Configuration\MagiumConfigurationFactory; |
|
7
|
|
|
use Symfony\Component\Console\Command\Command; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
11
|
|
|
|
|
12
|
|
|
class ContextList extends Command |
|
13
|
|
|
{ |
|
14
|
|
|
const TAB = ' '; |
|
15
|
|
|
const COMMAND = 'magium:configuration:list-contexts'; |
|
16
|
|
|
|
|
17
|
|
|
protected function configure() |
|
18
|
|
|
{ |
|
19
|
|
|
$this |
|
20
|
|
|
->setName(self::COMMAND) |
|
21
|
|
|
->setDescription('List contexts') |
|
22
|
|
|
->setHelp("This command lists the context hierarchy") |
|
23
|
|
|
; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
27
|
|
|
{ |
|
28
|
|
|
$output->writeln('Context List'); |
|
29
|
|
|
$output->writeln(['Following is list of contexts shown by inheritance', '']); |
|
30
|
|
|
$factory = new MagiumConfigurationFactory(); |
|
31
|
|
|
$contextFile = $factory->getContextFile(); |
|
32
|
|
|
$context = $contextFile->toXml(); |
|
33
|
|
|
$output->writeln($this->formatNode('default', 'Default')); |
|
34
|
|
|
foreach ($context->children() as $child) { |
|
35
|
|
|
$this->writeNode($child, $output); |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
protected function formatNode($id, $name = null) |
|
40
|
|
|
{ |
|
41
|
|
|
if ($name == null) { |
|
42
|
|
|
$name = $id; |
|
43
|
|
|
} |
|
44
|
|
|
return sprintf('%s (%s)', $id, $name); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
protected function writeNode(\SimpleXMLElement $element, OutputInterface $output, $tab = self::TAB) |
|
48
|
|
|
{ |
|
49
|
|
|
$id = (string)$element['id']; |
|
50
|
|
|
$title = (string)$element['title']; |
|
51
|
|
|
$output->writeln($tab . $this->formatNode($id, $title)); |
|
52
|
|
|
foreach ($element->children() as $child) { |
|
53
|
|
|
$this->writeNode($child, $output, $tab . self::TAB); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|