1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Magium\Configuration\Console\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
6
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
7
|
|
|
|
8
|
|
|
class ContextList extends AbstractCommand |
9
|
|
|
{ |
10
|
|
|
use ConfigurationFactoryTrait; |
11
|
|
|
|
12
|
|
|
const TAB = ' '; |
13
|
|
|
const COMMAND = 'magium:configuration:list-contexts'; |
14
|
|
|
|
15
|
3 |
|
protected function configure() |
16
|
|
|
{ |
17
|
|
|
$this |
18
|
3 |
|
->setName(self::COMMAND) |
19
|
3 |
|
->setDescription('List contexts') |
20
|
3 |
|
->setHelp("This command lists the context hierarchy") |
21
|
|
|
; |
22
|
3 |
|
} |
23
|
|
|
|
24
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
25
|
|
|
{ |
26
|
1 |
|
$output->writeln('Context List'); |
27
|
1 |
|
$output->writeln(['Following is list of contexts shown by inheritance', '']); |
|
|
|
|
28
|
1 |
|
$factory = $this->getConfigurationFactory(); |
29
|
1 |
|
$contextFile = $factory->getContextFile(); |
30
|
1 |
|
$context = $contextFile->toXml(); |
31
|
1 |
|
$output->writeln($this->formatNode('default', 'Default')); |
32
|
1 |
|
foreach ($context->children() as $child) { |
33
|
1 |
|
$this->writeNode($child, $output); |
34
|
|
|
} |
35
|
1 |
|
} |
36
|
|
|
|
37
|
1 |
|
protected function formatNode($id, $name = null) |
38
|
|
|
{ |
39
|
1 |
|
if ($name == null) { |
40
|
1 |
|
return $id; |
41
|
|
|
} |
42
|
1 |
|
return sprintf('%s (%s)', $id, $name); |
43
|
|
|
} |
44
|
|
|
|
45
|
1 |
|
protected function writeNode(\SimpleXMLElement $element, OutputInterface $output, $tab = self::TAB) |
46
|
|
|
{ |
47
|
1 |
|
$id = (string)$element['id']; |
48
|
1 |
|
$title = (string)$element['label']; |
49
|
1 |
|
$output->writeln($tab . $this->formatNode($id, $title)); |
50
|
1 |
|
foreach ($element->children() as $child) { |
51
|
1 |
|
$this->writeNode($child, $output, $tab . self::TAB); |
52
|
|
|
} |
53
|
1 |
|
} |
54
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: