protected function execute(InputInterface $input, OutputInterface $output) { $one = $this->getOption('one', $input); if ($one) { $output->writeln('Option one has a value of ' . $one); } $two = $this->getOption('two', $input); if ($two) { $output->writeln('Option two has a value of ' . $two); } $three = $this->getOption('three', $input); if ($three) { $output->writeln('Option three has a value of ' . $three); } parent::execute($input, $output); }
protected function execute(InputInterface $input, OutputInterface $output) { $file = $input->getArgument('file'); $skipIfMissing = $input->getOption('skip-if-missing'); $sourceExists = file_exists($file); if ($skipIfMissing && !$sourceExists) { $output->writeln('<info>Skipped as source file [' . $file . '] is missing.</info>'); return true; } if (!$sourceExists) { $output->writeln('<error>File [' . $file . '] does not exist.</error>'); return false; } if (!is_readable($file)) { $output->writeln('<error>File [' . $file . '] is not readable.</error>'); return false; } if (!is_writeable($file)) { $output->writeln('<error>File [' . $file . '] is not writeable.</error>'); return false; } $contents = file_get_contents($input->getArgument('file')); $count = 0; $out = str_replace($input->getArgument('old'), $input->getArgument('new'), $contents, $count); $output->writeln('<info>Made ' . $count . ' replacements.</info>'); $outputFile = $input->getArgument('output'); $outputFile = $outputFile ? $outputFile : $file; try { $exit = file_put_contents($outputFile, $out); } catch (\Exception $e) { $output->writeln('<error>Could not write to [' . $outputFile . '].</error>'); return false; } if (empty($exit)) { $output->writeln('<error>Could not write to [' . $outputFile . '].</error>'); return false; } $output->writeln('<info>Modified contents written to [' . $outputFile . '].</info>'); parent::execute($input, $output); return true; }
public function __construct($name = 'setup:local', YamlHasherInterface $yamlHasher = null) { parent::__construct($name); $this->yamlHasher = $yamlHasher ? $yamlHasher : new YamlHasher(); }
protected function execute(InputInterface $input, OutputInterface $output) { $host = $input->getOption('host'); $user = $input->getOption('user'); $pass = $input->getOption('pass'); $dbName = $input->getArgument('name'); try { $this->dump = $this->pdoFactory->makeDump($host, $user, $pass, $dbName); } catch (\PDOException $e) { throw new RuntimeException('Error while connecting to database [' . $dbName . ']: ' . $e->getMessage()); } if (false === $this->dump) { $output->writeln('<error>Something went wrong with the dump component instance.</error>'); return false; } \Codeception\Configuration::config(); if (!empty($input->getOption('dump-file'))) { $dumpFile = $input->getOption('dump-file'); } else { $dumpFile = codecept_data_dir($input->getArgument('snapshot') . '.sql'); } $output->writeln('<info>Dump file will be written to [' . $dumpFile . ']</info>'); if (!empty($input->getOption('dist-dump-file'))) { $distDumpFile = $input->getOption('dist-dump-file'); } else { $distDumpFile = codecept_data_dir($input->getArgument('snapshot') . '.dist.sql'); } $output->writeln('<info>Distribution version of dump file will be written to [' . $distDumpFile . ']</info>'); $skipTables = $input->getOption('skip-tables'); if (!empty($skipTables)) { $tables = explode(',', $skipTables); foreach ($tables as $table) { $this->dump->tables[$table] = \MySQLDump::NONE; } } $memory = fopen('php://memory', 'w'); $this->dump->write($memory); rewind($memory); $dumpContents = stream_get_contents($memory); if (!$this->filesystem->file_put_contents($dumpFile, $dumpContents)) { $output->writeln('<error>Could not write dump to [' . $dumpFile . ']</error>'); return false; } $output->writeln('<info>Dump file written to [' . $dumpFile . ']</info>'); $localUrl = $input->getOption('local-url'); $distUrl = $input->getOption('dist-url'); $localDomain = rtrim(preg_replace('~http(s)*:\\/\\/(www\\.)*~', '', $localUrl), '/'); $distDomain = rtrim(preg_replace('~http(s)*:\\/\\/(www\\.)*~', '', $distUrl), '/'); $distDumpContents = str_replace($localDomain, $distDomain, $dumpContents); if (!$this->filesystem->file_put_contents($distDumpFile, $distDumpContents)) { $output->writeln('<error>Could not write dist dump to [' . $distDumpFile . ']</error>'); return false; } $output->writeln('<info>Distribution version of dump file written to [' . $distDumpFile . ']</info>'); $output->writeln('<comment>Any occurrence of [' . $localDomain . '] in it was replaced with [' . $distDomain . ']</comment>'); parent::execute($input, $output); return true; }
protected function setUp() { BaseCommand::_resetConfig(); }