-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnvironment.php
72 lines (65 loc) · 2.29 KB
/
Environment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
namespace Hammer\ConfigManager\Console;
use Magento\Framework\App\DeploymentConfig\Writer;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Magento\framework\Config\File\ConfigFilePool;
/**
* Class Environment
* @package Hammer\ConsoleCommands\Console
*/
class Environment extends Command
{
/**
* Name argument
*/
const NAME_ARGUMENT = 'environment';
/**
* @var Writer
*/
private $deploymentConfig;
/**
* Environment constructor.
* @param Writer $deploymentConfig
*/
public function __construct(
Writer $deploymentConfig
)
{
$this->deploymentConfig = $deploymentConfig;
parent::__construct();
}
protected function configure()
{
$this->setName('hammer:environment:set')
->setDescription('Set up the environment which you are working on')
->setDefinition([
new InputArgument(
self::NAME_ARGUMENT,
InputArgument::OPTIONAL,
'environment [local, dev, stage, preprod, prod]'
),
]);
parent::configure();
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @throws \Magento\Framework\Exception\FileSystemException
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$environment = $input->getArgument(self::NAME_ARGUMENT);
if (is_null($environment)) {
throw new \InvalidArgumentException('Argument ' . self::NAME_ARGUMENT . ' is missing.');
}
if (($environment != 'local') && ($environment != 'dev') && ($environment != 'stage') && ($environment != 'preprod') && ($environment != 'prod')) {
throw new \InvalidArgumentException('Argument ' . self::NAME_ARGUMENT . ' should be local, dev, stage, prepod or prod.');
}
$this->deploymentConfig->saveConfig([ConfigFilePool::APP_ENV => ['hammer_environment' => $environment]]);
$output->writeln("<info>your environment is set as {$environment} </info>");
}
}