Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SetupEnvCommand.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types = 1);
7 
9 
10 use Symfony\Component\Console\Command\Command;
11 use Symfony\Component\Console\Input\InputOption;
12 use Symfony\Component\Console\Exception\InvalidOptionException;
13 use Symfony\Component\Console\Input\InputInterface;
14 use Symfony\Component\Console\Output\OutputInterface;
16 
17 class SetupEnvCommand extends Command
18 {
24  private $envProcessor;
25 
31  protected function configure()
32  {
33  $this->setName('setup:env')
34  ->setDescription("Generate .env file.");
35  $this->envProcessor = new EnvProcessor(TESTS_BP . DIRECTORY_SEPARATOR . '.env');
36  $env = $this->envProcessor->getEnv();
37  foreach ($env as $key => $value) {
38  $this->addOption($key, null, InputOption::VALUE_REQUIRED, '', $value);
39  }
40  }
41 
50  protected function execute(InputInterface $input, OutputInterface $output)
51  {
52  $config = $this->envProcessor->getEnv();
53  $userEnv = [];
54  foreach ($config as $key => $value) {
55  if ($input->getOption($key) === '') {
56  throw new InvalidOptionException(sprintf("Parameter $key cannot be empty.", $key));
57  }
58  $userEnv[$key] = $input->getOption($key);
59  }
60  $this->envProcessor->putEnvFile($userEnv);
61  $output->writeln(".env configuration successfully applied.");
62  }
63 }
execute(InputInterface $input, OutputInterface $output)
$config
Definition: fraud_order.php:17
$value
Definition: gender.phtml:16