/** * Execute command * * @param InputInterface $input Input instance * @param OutputInterface $output Output instance * * @return int|null|void * @throws \Exception */ public function execute(InputInterface $input, OutputInterface $output) { $cliSyncFilePath = getcwd() . '/' . AbstractCommand::CONFIG_FILE; if (file_exists($cliSyncFilePath)) { $this->output->writeln('<p-error>Configuration file ' . AbstractCommand::CONFIG_FILE . ' already exists</p-error>'); return 1; } // fetch example $content = PhpUtility::fileGetContents(CLITOOLS_ROOT_FS . '/conf/clisync.yml'); // store in current working dir PhpUtility::filePutContents($cliSyncFilePath, $content); // Start editor with file (if $EDITOR is set) try { $editor = new EditorCommandBuilder(); $editor->addArgument($cliSyncFilePath)->executeInteractive(); } catch (\Exception $e) { $this->output->writeln('<p-error>' . $e->getMessage() . '</p-error>'); } $this->output->writeln('<info>Successfully created ' . AbstractCommand::CONFIG_FILE . ' </info>'); }
/** * Add exclude (pattern) list to rsync command * * @param CommandBuilder $command Rsync Command * @param array $list List of excludes */ protected function rsyncAddExcludeList(CommandBuilder $command, $list) { $rsyncFilter = $this->tempDir . '/.rsync-exclude'; PhpUtility::filePutContents($rsyncFilter, implode("\n", $list)); $command->addArgumentTemplate('--exclude-from=%s', $rsyncFilter); // cleanup rsync file $command->getExecutor()->addFinisherCallback(function () use($rsyncFilter) { unlink($rsyncFilter); }); }
/** * Create docker instance from git repository * * @param string $path Path */ protected function initDocumentRoot($path) { $codePath = $path . '/code'; $dockerEnvFile = $path . '/docker-env.yml'; $documentRoot = null; // try to detect document root if (is_dir($codePath . '/html')) { $documentRoot = 'code/html'; } elseif (is_dir($codePath . '/htdocs')) { $documentRoot = 'code/htdocs'; } elseif (is_dir($codePath . '/Web')) { $documentRoot = 'code/Web'; } elseif (is_dir($codePath . '/web')) { $documentRoot = 'code/web'; } if ($documentRoot && is_file($dockerEnvFile)) { $dockerEnv = PhpUtility::fileGetContentsArray($dockerEnvFile); unset($line); foreach ($dockerEnv as &$line) { $line = preg_replace('/^[\\s]*DOCUMENT_ROOT[\\s]*=code\\/?[\\s]*$/ms', 'DOCUMENT_ROOT=' . $documentRoot, $line); } unset($line); $dockerEnv = implode("\n", $dockerEnv); PhpUtility::filePutContents($dockerEnvFile, $dockerEnv); } }