/**
  * @param \Composer\Package\Link[] $packageLinks
  * @param bool $ignoreRequiredVersion
  * @param bool $exactAsTilda
  * @return \Composer\Package\PackageInterface[]
  */
 private function getLatestPackages(array $packageLinks, $ignoreRequiredVersion = FALSE, $exactAsTilda = FALSE)
 {
     $packageIds = $this->policy->selectPreferredPackages($this->pool, [], $this->getLiterals($packageLinks, $ignoreRequiredVersion, $exactAsTilda));
     $packages = [];
     foreach ($packageIds as $packageId) {
         $package = $this->pool->packageById($packageId);
         $packages[$package->getName()] = $package;
     }
     return $packages;
 }
Example #2
0
 /**
  * @param  int   $level
  * @param  array $decisionQueue
  * @param  bool  $disableRules
  * @param  Rule  $rule
  * @return int
  */
 private function selectAndInstall($level, array $decisionQueue, $disableRules, Rule $rule)
 {
     // choose best package to install from decisionQueue
     $literals = $this->policy->selectPreferredPackages($this->pool, $this->installedMap, $decisionQueue, $rule->getRequiredPackage());
     $selectedLiteral = array_shift($literals);
     // if there are multiple candidates, then branch
     if (count($literals)) {
         $this->branches[] = array($literals, $level);
     }
     return $this->setPropagateLearn($level, $selectedLiteral, $disableRules, $rule);
 }
Example #3
0
 /**
  * @param Pool                        $pool
  * @param PolicyInterface             $policy
  * @param WritableRepositoryInterface $localRepo
  * @param array                       $repositories
  */
 private function processPackageUrls($pool, $policy, $localRepo, $repositories)
 {
     if (!$this->update) {
         return;
     }
     $rootRefs = $this->package->getReferences();
     foreach ($localRepo->getCanonicalPackages() as $package) {
         // find similar packages (name/version) in all repositories
         $matches = $pool->whatProvides($package->getName(), new Constraint('=', $package->getVersion()));
         foreach ($matches as $index => $match) {
             // skip local packages
             if (!in_array($match->getRepository(), $repositories, true)) {
                 unset($matches[$index]);
                 continue;
             }
             // skip providers/replacers
             if ($match->getName() !== $package->getName()) {
                 unset($matches[$index]);
                 continue;
             }
             $matches[$index] = $match->getId();
         }
         // select preferred package according to policy rules
         if ($matches && ($matches = $policy->selectPreferredPackages($pool, array(), $matches))) {
             $newPackage = $pool->literalToPackage($matches[0]);
             // update the dist and source URLs
             $sourceUrl = $package->getSourceUrl();
             $newSourceUrl = $newPackage->getSourceUrl();
             $newReference = $newPackage->getSourceReference();
             if ($package->isDev() && isset($rootRefs[$package->getName()]) && $package->getSourceReference() === $rootRefs[$package->getName()]) {
                 $newReference = $rootRefs[$package->getName()];
             }
             $this->updatePackageUrl($package, $newSourceUrl, $newPackage->getSourceType(), $newReference, $newPackage->getDistUrl());
             if ($package instanceof CompletePackage && $newPackage instanceof CompletePackage) {
                 $package->setAbandoned($newPackage->getReplacementPackage() ?: $newPackage->isAbandoned());
             }
         }
     }
 }
Example #4
0
 /**
  * @param Pool                        $pool
  * @param PolicyInterface             $policy
  * @param WritableRepositoryInterface $localRepo
  * @param array                       $repositories
  */
 private function processPackageUrls($pool, $policy, $localRepo, $repositories)
 {
     if (!$this->update) {
         return;
     }
     foreach ($localRepo->getCanonicalPackages() as $package) {
         // find similar packages (name/version) in all repositories
         $matches = $pool->whatProvides($package->getName(), new Constraint('=', $package->getVersion()));
         foreach ($matches as $index => $match) {
             // skip local packages
             if (!in_array($match->getRepository(), $repositories, true)) {
                 unset($matches[$index]);
                 continue;
             }
             // skip providers/replacers
             if ($match->getName() !== $package->getName()) {
                 unset($matches[$index]);
                 continue;
             }
             $matches[$index] = $match->getId();
         }
         // select preferred package according to policy rules
         if ($matches && ($matches = $policy->selectPreferredPackages($pool, array(), $matches))) {
             $newPackage = $pool->literalToPackage($matches[0]);
             // update the dist and source URLs
             $sourceUrl = $package->getSourceUrl();
             $newSourceUrl = $newPackage->getSourceUrl();
             if ($sourceUrl !== $newSourceUrl) {
                 $package->setSourceType($newPackage->getSourceType());
                 $package->setSourceUrl($newSourceUrl);
                 $package->setSourceReference($newPackage->getSourceReference());
             }
             // only update dist url for github/bitbucket dists as they use a combination of dist url + dist reference to install
             // but for other urls this is ambiguous and could result in bad outcomes
             if (preg_match('{^https?://(?:(?:www\\.)?bitbucket\\.org|(api\\.)?github\\.com)/}', $newPackage->getDistUrl())) {
                 $package->setDistUrl($newPackage->getDistUrl());
             }
         }
     }
 }