1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Magium\Configuration\Console\Command; |
4
|
|
|
|
5
|
|
|
use Magium\Configuration\Config\Config; |
6
|
|
|
use Magium\Configuration\MagiumConfigurationFactory; |
7
|
|
|
use Magium\Configuration\MagiumConfigurationFactoryInterface; |
8
|
|
|
use Symfony\Component\Console\Command\Command; |
9
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
11
|
|
|
use Symfony\Component\Console\Input\InputOption; |
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
13
|
|
|
|
14
|
|
|
class ConfigurationGet extends Command |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
const COMMAND = 'magium:configuration:get'; |
18
|
|
|
|
19
|
|
|
protected $factory; |
20
|
|
|
|
21
|
7 |
|
protected function configure() |
22
|
|
|
{ |
23
|
|
|
$this |
24
|
7 |
|
->setName(self::COMMAND) |
25
|
7 |
|
->setDescription('Get a configuration value') |
26
|
7 |
|
->setHelp("This command retrieves a value for a specific configuration path") |
27
|
|
|
; |
28
|
7 |
|
$this->addOption('use-flag', 'f', InputOption::VALUE_NONE, 'Get value as flag'); |
29
|
7 |
|
$this->addArgument('path', InputArgument::REQUIRED, 'Configuration Path'); |
30
|
7 |
|
$this->addArgument('context', InputArgument::OPTIONAL, 'Configuration Context', Config::CONTEXT_DEFAULT); |
31
|
7 |
|
} |
32
|
|
|
|
33
|
6 |
|
public function setConfigurationFactory(MagiumConfigurationFactoryInterface $factory) |
34
|
|
|
{ |
35
|
6 |
|
$this->factory = $factory; |
36
|
6 |
|
} |
37
|
|
|
|
38
|
6 |
|
protected function getConfigurationFactory() |
39
|
|
|
{ |
40
|
6 |
|
if (!$this->factory instanceof MagiumConfigurationFactoryInterface) { |
41
|
|
|
$this->factory = new MagiumConfigurationFactory(); |
42
|
|
|
} |
43
|
6 |
|
return $this->factory; |
44
|
|
|
} |
45
|
|
|
|
46
|
6 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
47
|
|
|
{ |
48
|
6 |
|
$factory = $this->getConfigurationFactory(); |
49
|
6 |
|
$manager = $factory->getManager(); |
50
|
6 |
|
$path = $input->getArgument('path'); |
51
|
6 |
|
$context = $input->getArgument('context'); |
52
|
6 |
|
$config = $manager->getConfiguration($context); |
53
|
6 |
|
$useFlag = $input->getOption('use-flag'); |
54
|
6 |
|
if ($useFlag) { |
55
|
2 |
|
$value = $config->getValueFlag($path); |
56
|
2 |
|
if ($value) { |
57
|
1 |
|
$value = 'flag:true'; |
58
|
|
|
} else { |
59
|
2 |
|
$value = 'flag:false'; |
60
|
|
|
} |
61
|
|
|
} else { |
62
|
4 |
|
$value = $config->getValue($path); |
63
|
4 |
|
if (is_null($value)) { |
64
|
1 |
|
$value = '<null>'; |
65
|
3 |
|
} else if (!is_string($value) && !is_numeric($value)) { |
66
|
1 |
|
ob_start(); |
67
|
1 |
|
var_dump($value); |
|
|
|
|
68
|
1 |
|
$value = ob_get_clean(); |
69
|
1 |
|
$value = trim($value); |
70
|
2 |
|
} else if ($value == '') { |
71
|
1 |
|
$value = '<empty>'; |
72
|
|
|
} |
73
|
|
|
} |
74
|
6 |
|
$out = sprintf("Value for %s (context: %s): %s", $path, $context, $value); |
75
|
|
|
|
76
|
6 |
|
$output->writeln($out); |
77
|
6 |
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
} |
81
|
|
|
|