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
|
|
|
use ConfigurationFactoryTrait; |
15
|
|
|
|
16
|
|
|
const TAB = ' '; |
17
|
|
|
const COMMAND = 'magium:configuration:list-contexts'; |
18
|
|
|
|
19
|
3 |
|
protected function configure() |
20
|
|
|
{ |
21
|
|
|
$this |
22
|
3 |
|
->setName(self::COMMAND) |
23
|
3 |
|
->setDescription('List contexts') |
24
|
3 |
|
->setHelp("This command lists the context hierarchy") |
25
|
|
|
; |
26
|
3 |
|
} |
27
|
|
|
|
28
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
29
|
|
|
{ |
30
|
1 |
|
$output->writeln('Context List'); |
31
|
1 |
|
$output->writeln(['Following is list of contexts shown by inheritance', '']); |
32
|
1 |
|
$factory = $this->getConfigurationFactory(); |
33
|
1 |
|
$contextFile = $factory->getContextFile(); |
34
|
1 |
|
$context = $contextFile->toXml(); |
35
|
1 |
|
$output->writeln($this->formatNode('default', 'Default')); |
36
|
1 |
|
foreach ($context->children() as $child) { |
37
|
1 |
|
$this->writeNode($child, $output); |
38
|
|
|
} |
39
|
1 |
|
} |
40
|
|
|
|
41
|
1 |
|
protected function formatNode($id, $name = null) |
42
|
|
|
{ |
43
|
1 |
|
if ($name == null) { |
44
|
1 |
|
return $id; |
45
|
|
|
} |
46
|
1 |
|
return sprintf('%s (%s)', $id, $name); |
47
|
|
|
} |
48
|
|
|
|
49
|
1 |
|
protected function writeNode(\SimpleXMLElement $element, OutputInterface $output, $tab = self::TAB) |
50
|
|
|
{ |
51
|
1 |
|
$id = (string)$element['id']; |
52
|
1 |
|
$title = (string)$element['title']; |
53
|
1 |
|
$output->writeln($tab . $this->formatNode($id, $title)); |
54
|
1 |
|
foreach ($element->children() as $child) { |
55
|
1 |
|
$this->writeNode($child, $output, $tab . self::TAB); |
56
|
|
|
} |
57
|
1 |
|
} |
58
|
|
|
|
59
|
|
|
} |
60
|
|
|
|