示例#1
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());
             }
         }
     }
 }
示例#2
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());
             }
         }
     }
 }