/** * @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'); }
/** * @param $name * @return array|null */ private function getPackageInfo($name) { $moduleRepository = new ModuleRepository($this->workingDir); $package = $moduleRepository->getPackage($name); if (!$package) { return null; } $result = array('name' => $package->getName(), 'description' => $package->getDescription(), 'installed' => null, 'versions' => array()); $installed = $moduleRepository->getInstalledByName($package->getName()); if ($installed) { $branchAlias = ''; $version = $installed->getPrettyVersion(); if ($installed instanceof \Composer\Package\AliasPackage) { $branchAlias = $version; $version = $installed->getAliasOf()->getPrettyVersion(); } $require = array(); foreach ($installed->getRequires() as $link) { /* @var \Composer\Package\Link $link */ $require[$link->getTarget()] = $link->getConstraint()->getPrettyString(); } $result['installed'] = array('version' => $version, 'branchAlias' => $branchAlias, 'reference' => $installed->getSourceReference(), 'isDependency' => $moduleRepository->isInstalledAsDependency($installed->getName()), 'require' => $require); } $versions = $package->getVersions(); foreach ($versions as $p) { /* @var \Packagist\Api\Result\Package\Version $p */ $createdAt = new \DateTime($p->getTime()); $version = $p->getVersion(); $result['versions'][$version] = array('version' => $version, 'branchAlias' => $moduleRepository->getVersionAlias($p), 'reference' => $p->getSource()->getReference(), 'createdAt' => $createdAt->format(\DateTime::RFC1123), 'require' => $p->getRequire()); } return $result; }