/** * {@inheritdoc} */ public function getOutput(OperationInterface $operation, UrlGenerator $urlGenerator = null) { if (!$operation instanceof UpdateOperation) { throw new \LogicException('Operation should be an instance of UpdateOperation'); } $output = []; $initialPackage = $operation->getInitialPackage(); $targetPackage = $operation->getTargetPackage(); $versionFrom = new Version($initialPackage->getVersion(), $initialPackage->getPrettyVersion(), method_exists($initialPackage, 'getFullPrettyVersion') ? $initialPackage->getFullPrettyVersion() : VersionParser::formatVersion($initialPackage)); $versionTo = new Version($targetPackage->getVersion(), $targetPackage->getPrettyVersion(), method_exists($targetPackage, 'getFullPrettyVersion') ? $targetPackage->getFullPrettyVersion() : VersionParser::formatVersion($targetPackage)); $action = 'updated'; if (Comparator::greaterThan($versionFrom->getName(), $versionTo->getName())) { $action = 'downgraded'; } $output[] = sprintf(' - <fg=green>%s</fg=green> %s from <fg=yellow>%s</fg=yellow> to <fg=yellow>%s</fg=yellow>', $initialPackage->getName(), $action, $versionFrom->getPretty(), $versionTo->getPretty()); if ($urlGenerator) { $compareUrl = $urlGenerator->generateCompareUrl($initialPackage->getSourceUrl(), $versionFrom, $targetPackage->getSourceUrl(), $versionTo); if (!empty($compareUrl)) { $output[] = sprintf(' See changes: %s', $compareUrl); } $releaseUrl = $urlGenerator->generateReleaseUrl($this->extractSourceUrl($operation), $versionTo); if (!empty($releaseUrl)) { $output[] = sprintf(' Release notes: %s', $releaseUrl); } } return $output; }
/** * Get the package defined in the composer operation. * * @param OperationInterface $operation The operation * * @return PackageInterface|null Return NULL if the operation is not INSTALL or UPDATE */ protected static function getOperationPackage(OperationInterface $operation) { $data = null; if ($operation instanceof UpdateOperation) { $data = $operation->getTargetPackage(); } elseif ($operation instanceof InstallOperation) { $data = $operation->getPackage(); } return $data; }
/** * Get the package from a given operation * * Is needed because update operations don't have a getPackage method * * @access protected * @param OperationInterface $operation The operation * @return PackageInterface The package of the operation */ protected function getPackageFromOperation(OperationInterface $operation) { if ($operation->getJobType() === 'update') { return $operation->getTargetPackage(); } return $operation->getPackage(); }
/** * Get a Package object from an OperationInterface object. * * @param OperationInterface $operation * @return PackageInterface * @throws \Exception */ protected function getPackageFromOperation(OperationInterface $operation) { if ($operation instanceof InstallOperation) { $package = $operation->getPackage(); } elseif ($operation instanceof UpdateOperation) { $package = $operation->getTargetPackage(); } else { throw new \Exception('Unknown operation: ' . get_class($operation)); } return $package; }
/** * Add job by operation type. * * @param OperationInterface $operation * @param \Closure $install * @param \Closure $update * @param \Closure $uninstall */ protected static function addJobByOperationType(OperationInterface $operation, \Closure $install, \Closure $uninstall, \Closure $update = null) { switch ($operation->getJobType()) { case 'install': self::getContainer()->addJob($install($operation->getPackage())); break; case 'uninstall': self::getContainer()->addJob($uninstall($operation->getPackage())); break; case 'update': $update = $update ?: $install; self::getContainer()->addJob($update($operation->getTargetPackage())); break; } }