示例#1
0
 public function versionCompare(PackageInterface $a, PackageInterface $b, $operator)
 {
     if ($this->preferStable && ($stabA = $a->getStability()) !== ($stabB = $b->getStability())) {
         return BasePackage::$stabilities[$stabA] < BasePackage::$stabilities[$stabB];
     }
     $constraint = new VersionConstraint($operator, $b->getVersion());
     $version = new VersionConstraint('==', $a->getVersion());
     return $constraint->matchSpecific($version, true);
 }
示例#2
0
 /**
  * Convert a package version into string representation.
  *
  * @param PackageInterface $package       The package to extract the version from.
  *
  * @param bool             $fullReference Flag if the complete reference shall be added or an abbreviated form.
  *
  * @return string
  *
  * @throws \RuntimeException If the package is a dev package and does not have valid reference information.
  */
 public static function convertPackageVersion(PackageInterface $package, $fullReference = false)
 {
     $version = $package->getPrettyVersion();
     if ('dev' === $package->getStability()) {
         if (null === ($reference = $package->getDistReference())) {
             if (null === ($reference = $package->getSourceReference())) {
                 throw new \RuntimeException('Unable to determine reference for ' . $package->getPrettyName());
             }
         }
         $version .= '#' . (!$fullReference ? substr($reference, 0, 8) : $reference);
     }
     return $version;
 }
 /**
  * Given a concrete version, this returns a ~ constraint (when possible)
  * that should be used, for example, in composer.json.
  *
  * For example:
  *  * 1.2.1         -> ~1.2
  *  * 1.2           -> ~1.2
  *  * v3.2.1        -> ~3.2
  *  * 2.0-beta.1    -> ~2.0@beta
  *  * dev-master    -> ~2.1@dev      (dev version with alias)
  *  * dev-master    -> dev-master    (dev versions are untouched)
  *
  * @param PackageInterface $package
  * @return string
  */
 public function findRecommendedRequireVersion(PackageInterface $package)
 {
     $version = $package->getVersion();
     if (!$package->isDev()) {
         return $this->transformVersion($version, $package->getPrettyVersion(), $package->getStability());
     }
     $loader = new ArrayLoader($this->getParser());
     $dumper = new ArrayDumper();
     $extra = $loader->getBranchAlias($dumper->dump($package));
     if ($extra) {
         $extra = preg_replace('{^(\\d+\\.\\d+\\.\\d+)(\\.9999999)-dev$}', '$1.0', $extra, -1, $count);
         if ($count) {
             $extra = str_replace('.9999999', '.0', $extra);
             return $this->transformVersion($extra, $extra, 'dev');
         }
     }
     return $package->getPrettyVersion();
 }
示例#4
0
文件: package.php 项目: wp-cli/wp-cli
 /**
  * Given a package, this finds the latest package matching it
  *
  * @param  PackageInterface $package
  * @param  Composer         $composer
  * @param  string           $phpVersion
  * @param  bool             $minorOnly
  *
  * @return PackageInterface|null
  */
 private function find_latest_package(PackageInterface $package, Composer $composer, $phpVersion, $minorOnly = false)
 {
     // find the latest version allowed in this pool
     $name = $package->getName();
     $versionSelector = new VersionSelector($this->get_pool($composer));
     $stability = $composer->getPackage()->getMinimumStability();
     $flags = $composer->getPackage()->getStabilityFlags();
     if (isset($flags[$name])) {
         $stability = array_search($flags[$name], BasePackage::$stabilities, true);
     }
     $bestStability = $stability;
     if ($composer->getPackage()->getPreferStable()) {
         $bestStability = $package->getStability();
     }
     $targetVersion = null;
     if (0 === strpos($package->getVersion(), 'dev-')) {
         $targetVersion = $package->getVersion();
     }
     if ($targetVersion === null && $minorOnly) {
         $targetVersion = '^' . $package->getVersion();
     }
     return $versionSelector->findBestCandidate($name, $targetVersion, $phpVersion, $bestStability);
 }
示例#5
0
 /**
  * Checks if the package matches the given constraint directly or through
  * provided or replaced packages
  *
  * @param  array|PackageInterface $candidate
  * @param  string                 $name       Name of the package to be matched
  * @param  ConstraintInterface    $constraint The constraint to verify
  * @return int                    One of the MATCH* constants of this class or 0 if there is no match
  */
 private function match($candidate, $name, ConstraintInterface $constraint = null)
 {
     $candidateName = $candidate->getName();
     $candidateVersion = $candidate->getVersion();
     $isDev = $candidate->getStability() === 'dev';
     $isAlias = $candidate instanceof AliasPackage;
     if (!$isDev && !$isAlias && isset($this->filterRequires[$name])) {
         $requireFilter = $this->filterRequires[$name];
     } else {
         $requireFilter = new EmptyConstraint();
     }
     if ($candidateName === $name) {
         $pkgConstraint = new Constraint('==', $candidateVersion);
         if ($constraint === null || $constraint->matches($pkgConstraint)) {
             return $requireFilter->matches($pkgConstraint) ? self::MATCH : self::MATCH_FILTERED;
         }
         return self::MATCH_NAME;
     }
     $provides = $candidate->getProvides();
     $replaces = $candidate->getReplaces();
     // aliases create multiple replaces/provides for one target so they can not use the shortcut below
     if (isset($replaces[0]) || isset($provides[0])) {
         foreach ($provides as $link) {
             if ($link->getTarget() === $name && ($constraint === null || $constraint->matches($link->getConstraint()))) {
                 return $requireFilter->matches($link->getConstraint()) ? self::MATCH_PROVIDE : self::MATCH_FILTERED;
             }
         }
         foreach ($replaces as $link) {
             if ($link->getTarget() === $name && ($constraint === null || $constraint->matches($link->getConstraint()))) {
                 return $requireFilter->matches($link->getConstraint()) ? self::MATCH_REPLACE : self::MATCH_FILTERED;
             }
         }
         return self::MATCH_NONE;
     }
     if (isset($provides[$name]) && ($constraint === null || $constraint->matches($provides[$name]->getConstraint()))) {
         return $requireFilter->matches($provides[$name]->getConstraint()) ? self::MATCH_PROVIDE : self::MATCH_FILTERED;
     }
     if (isset($replaces[$name]) && ($constraint === null || $constraint->matches($replaces[$name]->getConstraint()))) {
         return $requireFilter->matches($replaces[$name]->getConstraint()) ? self::MATCH_REPLACE : self::MATCH_FILTERED;
     }
     return self::MATCH_NONE;
 }
示例#6
0
 /**
  * {@inheritdoc}
  */
 public function getStability()
 {
     return $this->package->getStability();
 }
 /**
  * Returns the Drupal core version for the given package.
  *
  * @param \Composer\Package\PackageInterface $drupalCorePackage
  *
  * @return string
  */
 protected function getDrupalCoreVersion(PackageInterface $drupalCorePackage)
 {
     $version = $drupalCorePackage->getPrettyVersion();
     if ($drupalCorePackage->getStability() == 'dev' && substr($version, -4) == '-dev') {
         $version = substr($version, 0, -4);
         return $version;
     }
     return $version;
 }