Example #1
0
 /**
  * Finds the package with the given name.
  *
  * @param string $name The name of the package to lookup.
  * @param ConstraintInterface $constraint The constraint of the package to lookup.
  * @return PackageInterface|null Returns null when no package has been found.
  */
 public function findPackage($name, ConstraintInterface $constraint)
 {
     $this->load();
     foreach ($this->packages as $packageName => $packageVersions) {
         if ($packageName !== $name) {
             continue;
         }
         foreach ($packageVersions as $packageVersion => $package) {
             $pkgConstraint = $this->versionParser->parseConstraints($packageVersion);
             if ($constraint->matches($pkgConstraint)) {
                 $package['name'] = $packageName;
                 $package['version'] = $packageVersion;
                 return $this->buildPackage($package);
             }
         }
     }
     return null;
 }
Example #2
0
 /**
  * Turns a constraint into text usable in a sentence describing a job
  *
  * @param  \Composer\Semver\Constraint\ConstraintInterface $constraint
  * @return string
  */
 protected function constraintToText($constraint)
 {
     return $constraint ? ' ' . $constraint->getPrettyString() : '';
 }
Example #3
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;
 }
Example #4
0
 /**
  * @param  PackageInterface $sourcePackage
  * @return string
  */
 public function getPrettyString(PackageInterface $sourcePackage)
 {
     return $sourcePackage->getPrettyString() . ' ' . $this->description . ' ' . $this->target . ' ' . $this->constraint->getPrettyString() . '';
 }