1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Magium\Configuration\Console\Command; |
4
|
|
|
|
5
|
|
|
use Magium\Configuration\Config\Config; |
6
|
|
|
use Magium\Configuration\Config\ConfigInterface; |
7
|
|
|
use Magium\Configuration\MagiumConfigurationFactory; |
8
|
|
|
use Magium\Configuration\MagiumConfigurationFactoryInterface; |
9
|
|
|
use Symfony\Component\Console\Command\Command; |
10
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
12
|
|
|
use Symfony\Component\Console\Input\InputOption; |
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
14
|
|
|
|
15
|
|
|
class ConfigurationSet extends Command |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
const COMMAND = 'magium:configuration:set'; |
19
|
|
|
|
20
|
|
|
protected $factory; |
21
|
|
|
|
22
|
2 |
View Code Duplication |
protected function configure() |
23
|
|
|
{ |
24
|
|
|
$this |
25
|
2 |
|
->setName(self::COMMAND) |
26
|
2 |
|
->setDescription('Set a configuration value') |
27
|
2 |
|
->setHelp("This command sets a value for a specific configuration path") |
28
|
|
|
; |
29
|
|
|
|
30
|
2 |
|
$this->addArgument('path', InputArgument::REQUIRED, 'Configuration Path'); |
31
|
2 |
|
$this->addArgument('value', InputArgument::REQUIRED, 'Value'); |
32
|
2 |
|
$this->addArgument('context', InputArgument::OPTIONAL, 'Configuration Context', Config::CONTEXT_DEFAULT); |
33
|
2 |
|
} |
34
|
|
|
|
35
|
1 |
|
public function setConfigurationFactory(MagiumConfigurationFactoryInterface $factory) |
36
|
|
|
{ |
37
|
1 |
|
$this->factory = $factory; |
38
|
1 |
|
} |
39
|
|
|
|
40
|
1 |
|
protected function getConfigurationFactory() |
41
|
|
|
{ |
42
|
1 |
|
if (!$this->factory instanceof MagiumConfigurationFactoryInterface) { |
43
|
|
|
$this->factory = new MagiumConfigurationFactory(); |
44
|
|
|
} |
45
|
1 |
|
return $this->factory; |
46
|
|
|
} |
47
|
|
|
|
48
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
49
|
|
|
{ |
50
|
1 |
|
$factory = $this->getConfigurationFactory(); |
51
|
1 |
|
$builderFactory = $factory->getBuilderFactory(); |
52
|
1 |
|
$path = $input->getArgument('path'); |
53
|
1 |
|
$value = $input->getArgument('value'); |
54
|
1 |
|
$context = $input->getArgument('context'); |
55
|
1 |
|
$builderFactory->getPersistence()->setValue($path, $value, $context); |
56
|
|
|
|
57
|
1 |
|
$out = sprintf("Set %s to %s (context: %s)", $path, $value, $context); |
58
|
|
|
|
59
|
1 |
|
$output->writeln($out); |
60
|
1 |
|
$output->writeln("Don't forget to rebuild your configuration cache with " . ConfigurationBuild::COMMAND); |
61
|
1 |
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
} |
65
|
|
|
|