/** * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $name = $input->getArgument('name'); $version = $input->getArgument('version'); $method = $input->getOption('method'); $outputUrl = $input->getOption('output-url'); if (!in_array($method, array('require', 'remove'))) { $output->writeln('<error>Method "' . $method . '" not allowed</error>'); return 1; } $status = array('success' => false, 'working' => true, 'msg' => ''); $workingDir = $this->getWorkingDir($input); $moduleRepository = new ModuleRepository($workingDir); $remoteOutput = new RemoteOutput(function ($message) use(&$status, $output, $outputUrl) { $output->write($message); if ($outputUrl) { file_get_contents($outputUrl . '?' . http_build_query(array('success' => $status['success'], 'working' => $status['working'], 'msg' => $message))); } }); $isSuccess = false; if ('require' == $method) { $package = $moduleRepository->getPackage($name); if ($package) { $isSuccess = $moduleRepository->requirePackage($name, $version ?: 'dev-master', $remoteOutput); } else { $remoteOutput->writeln('Package not found.'); } } else { if ('remove' == $method) { $isSuccess = $moduleRepository->removePackage($name, $remoteOutput); } } $status['success'] = $isSuccess; $status['working'] = false; $remoteOutput->writeln($isSuccess ? 'Finished: SUCCESS' : 'Finished: FAILURE'); }