/** * {@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; }
/** * {@inheritdoc} */ public function getOutput(OperationInterface $operation, UrlGenerator $urlGenerator = null) { if (!$operation instanceof UninstallOperation) { throw new \LogicException('Operation should be an instance of UninstallOperation'); } $output = []; $package = $operation->getPackage(); $version = new Version($package->getVersion(), $package->getPrettyVersion(), method_exists($package, 'getFullPrettyVersion') ? $package->getFullPrettyVersion() : VersionParser::formatVersion($package)); $output[] = sprintf(' - <fg=green>%s</fg=green> removed (installed version was <fg=yellow>%s</fg=yellow>)', $package->getName(), $version->getPretty()); return $output; }
/** * {@inheritdoc} */ public function getOutput(OperationInterface $operation, UrlGenerator $urlGenerator = null) { if (!$operation instanceof FakeOperation) { return []; } $output = [' - ' . $this->output . ', ' . $operation->getText()]; if ($urlGenerator) { $output[] = ' ' . $urlGenerator->generateCompareUrl($this->sourceUrl, new Version('', '', ''), $this->sourceUrl, new Version('', '', '')); $output[] = ' ' . $urlGenerator->generateReleaseUrl($this->sourceUrl, new Version('', '', '')); } return $output; }
/** * @param string $composerType * * @return PackageEvent */ protected function createEvent($composerType) { $this->package->expects($this->any())->method('getType')->will($this->returnValue($composerType)); $this->operation->expects($this->any())->method('getTargetPackage')->will($this->returnValue($this->package)); $this->operation->expects($this->any())->method('getPackage')->will($this->returnValue($this->package)); return new PackageEvent('foo-event', $this->composer, $this->io, true, $this->operation); }
/** * {@inheritdoc} */ public function getOutput(OperationInterface $operation, UrlGenerator $urlGenerator = null) { if (!$operation instanceof InstallOperation) { throw new \LogicException('Operation should be an instance of InstallOperation'); } $output = []; $package = $operation->getPackage(); $version = new Version($package->getVersion(), $package->getPrettyVersion(), method_exists($package, 'getFullPrettyVersion') ? $package->getFullPrettyVersion() : VersionParser::formatVersion($package)); $output[] = sprintf(' - <fg=green>%s</fg=green> installed in version <fg=yellow>%s</fg=yellow>', $package->getName(), $version->getPretty()); if ($urlGenerator) { $releaseUrl = $urlGenerator->generateReleaseUrl($this->extractSourceUrl($operation), $version); if (!empty($releaseUrl)) { $output[] = sprintf(' Release notes: %s', $releaseUrl); } } return $output; }
/** * @param string $composerType * * @return PackageEvent */ protected function createEvent($composerType) { $this->package->expects($this->any())->method('getType')->will($this->returnValue($composerType)); $this->operation->expects($this->any())->method('getTargetPackage')->will($this->returnValue($this->package)); $this->operation->expects($this->any())->method('getPackage')->will($this->returnValue($this->package)); /* @var PolicyInterface $policy */ $policy = $this->getMock('Composer\\DependencyResolver\\PolicyInterface'); /* @var Pool $pool */ $pool = $this->getMockBuilder('Composer\\DependencyResolver\\Pool')->disableOriginalConstructor()->getMock(); /* @var CompositeRepository $installedRepo */ $installedRepo = $this->getMockBuilder('Composer\\Repository\\CompositeRepository')->disableOriginalConstructor()->getMock(); /* @var Request $request */ $request = $this->getMockBuilder('Composer\\DependencyResolver\\Request')->disableOriginalConstructor()->getMock(); $operations = array($this->getMock('Composer\\DependencyResolver\\Operation\\OperationInterface')); return new PackageEvent('foo-event', $this->composer, $this->io, true, $policy, $pool, $installedRepo, $request, $operations, $this->operation); }
/** * Executes solver operation. * * @param RepositoryInterface $repo repository in which to check * @param OperationInterface $operation operation instance */ public function execute(RepositoryInterface $repo, OperationInterface $operation) { $method = $operation->getJobType(); $this->{$method}($repo, $operation); }
/** * Executes solver operation. * * @param OperationInterface $operation operation instance */ public function execute(OperationInterface $operation) { $method = $operation->getJobType(); $this->{$method}($operation); }
/** * 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; } }
/** * Convert reason to text. * * @param OperationInterface $operation The operation to obtain the reason from. * * @return string|null */ private function getReason(OperationInterface $operation) { if (!$this->pool) { return null; } $reason = $operation->getReason(); if ($reason instanceof Rule) { switch ($reason->getReason()) { case Rule::RULE_JOB_INSTALL: return 'Required by the root package: ' . $reason->getPrettyString($this->pool); case Rule::RULE_PACKAGE_REQUIRES: return $reason->getPrettyString($this->pool); default: } } return null; }