'.env.docker', 'prod-v2' => '.env.prod', 'test-v2' => '.env.test', 'test1' => '.env.test1', 'test2' => '.env.test2', 'test3' => '.env.test3', 'test4' => '.env.test4', 'test5' => '.env.test5', 'ci' => '.env.staging', ]; private string $projectDir; #[Required] public function setProjectDir(string $projectDir): void { $this->projectDir = $projectDir; } /** * Configures the command. */ protected function configure(): void { $this->addOption( 'host', null, InputOption::VALUE_REQUIRED, "Use this hostname instead of the current's host name." ); } protected function execute(InputInterface $input, OutputInterface $output): int { if ($input->getOption('host')) { $hostname = $input->getOption('host'); } elseif (getenv('HOST')) { $hostname = getenv('HOST'); } else { $hostname = gethostname(); } if (!array_key_exists($hostname, self::ENVIRONMENTS_FILES)) { throw new \RuntimeException('Critical : unknown environment ['.$hostname.']'); } $envFile = Path::join($this->projectDir, 'env', self::ENVIRONMENTS_FILES[$hostname]); $symlinkLocation = Path::join($this->projectDir, '.env.local'); if (file_exists($symlinkLocation)) { unlink($symlinkLocation); $output->writeln($symlinkLocation.' was deleted'); } symlink($envFile, $symlinkLocation); $output->writeln('Symlink created : '.$symlinkLocation.' => '.$envFile); return Command::SUCCESS; } }