1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Magium\Configuration\Console\Command; |
4
|
|
|
|
5
|
|
|
use Magium\Configuration\Config\Repository\ConfigurationRepository; |
6
|
|
|
use Symfony\Component\Console\Command\Command; |
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
|
11
|
|
|
class ConfigurationSet extends Command |
12
|
|
|
{ |
13
|
|
|
use ConfigurationFactoryTrait; |
14
|
|
|
|
15
|
|
|
const COMMAND = 'magium:configuration:set'; |
16
|
|
|
|
17
|
3 |
View Code Duplication |
protected function configure() |
18
|
|
|
{ |
19
|
|
|
$this |
20
|
3 |
|
->setName(self::COMMAND) |
21
|
3 |
|
->setDescription('Set a configuration value') |
22
|
3 |
|
->setHelp("This command sets a value for a specific configuration path") |
23
|
|
|
; |
24
|
|
|
|
25
|
3 |
|
$this->addArgument('path', InputArgument::REQUIRED, 'Configuration Path'); |
26
|
3 |
|
$this->addArgument('value', InputArgument::OPTIONAL, 'Value'); |
27
|
3 |
|
$this->addArgument('context', InputArgument::OPTIONAL, 'Configuration Context', ConfigurationRepository::CONTEXT_DEFAULT); |
28
|
3 |
|
} |
29
|
|
|
|
30
|
|
|
|
31
|
2 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
32
|
|
|
{ |
33
|
2 |
|
$factory = $this->getConfigurationFactory(); |
34
|
2 |
|
$builderFactory = $factory->getBuilderFactory(); |
|
|
|
|
35
|
2 |
|
$path = $input->getArgument('path'); |
36
|
2 |
|
$value = $input->getArgument('value'); |
37
|
2 |
|
$context = $input->getArgument('context'); |
38
|
|
|
|
39
|
2 |
|
$structure = $factory->getBuilder()->getMergedStructure(); |
40
|
|
|
|
41
|
2 |
|
$structure->registerXPathNamespace('s', 'http://www.magiumlib.com/Configuration'); |
42
|
2 |
|
$paths = explode('/', $path); |
43
|
2 |
|
$xpath = '/'; |
44
|
2 |
|
foreach ($paths as $pathName) { |
45
|
2 |
|
$xpath .= sprintf('/s:*[@identifier="%s"]', $pathName); |
46
|
|
|
} |
47
|
|
|
|
48
|
2 |
|
$results = $structure->xpath($xpath); |
49
|
2 |
|
if (!$results) { |
|
|
|
|
50
|
1 |
|
throw new UnconfiguredPathException(sprintf('Path (%s) is not configured. Do you need to create a configuration file?', $path)); |
51
|
|
|
} |
52
|
|
|
|
53
|
1 |
|
$builderFactory->getBuilder()->setValue($path, $value, $context); |
54
|
|
|
|
55
|
1 |
|
if (!$value) { |
56
|
|
|
$value = '<empty>'; |
57
|
|
|
} |
58
|
|
|
|
59
|
1 |
|
$out = sprintf("Set %s to %s (context: %s)", $path, $value, $context); |
60
|
|
|
|
61
|
1 |
|
$output->writeln($out); |
62
|
1 |
|
$output->writeln("Don't forget to rebuild your configuration cache with " . ConfigurationBuild::COMMAND); |
63
|
1 |
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.