|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Magium\Configuration\Console\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Magium\Configuration\Config\InvalidContextException; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
9
|
|
|
|
|
10
|
|
|
class ConfigurationBuild extends AbstractCommand |
|
11
|
|
|
{ |
|
12
|
|
|
use ConfigurationFactoryTrait; |
|
13
|
|
|
|
|
14
|
|
|
const COMMAND = 'magium:configuration:build'; |
|
15
|
|
|
|
|
16
|
8 |
|
protected function configure() |
|
17
|
|
|
{ |
|
18
|
|
|
$this |
|
19
|
8 |
|
->setName(self::COMMAND) |
|
20
|
8 |
|
->setDescription('Build configuration') |
|
21
|
8 |
|
->setHelp( |
|
22
|
|
|
'This command will build the configuration object based off of configuration files and ' |
|
23
|
|
|
. 'persistent storage data. By default, it will rebuild all contexts, but you can specify an ' |
|
24
|
8 |
|
. 'individual context if you so like.'); |
|
25
|
|
|
|
|
26
|
8 |
|
$this->addArgument('context', InputArgument::OPTIONAL, 'Configuration Context (ignore to build all contexts)'); |
|
27
|
8 |
|
} |
|
28
|
|
|
|
|
29
|
4 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
30
|
|
|
{ |
|
31
|
4 |
|
$factory = $this->getConfigurationFactory(); |
|
32
|
4 |
|
$builder = $factory->getBuilder(); |
|
33
|
4 |
|
$manager = $factory->getManager(); |
|
34
|
4 |
|
$contexts = $factory->getContextFile()->getContexts(); |
|
35
|
4 |
|
$context = $input->getArgument('context'); |
|
36
|
4 |
|
if ($context) { |
|
37
|
2 |
|
if (in_array($context, $contexts)) { |
|
38
|
1 |
|
$contexts = [$context]; |
|
39
|
|
|
} else { |
|
40
|
1 |
|
throw new InvalidContextException('Context does not exist: ' . $context); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
3 |
|
foreach ($contexts as $context) { |
|
44
|
3 |
|
$output->writeln('Building context: ' . $context); |
|
45
|
3 |
|
$config = $builder->build($context); |
|
46
|
3 |
|
$manager->storeConfigurationObject($config, $context); |
|
47
|
|
|
} |
|
48
|
3 |
|
} |
|
49
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|