Esempio n. 1
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  LinkConstraintInterface $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, LinkConstraintInterface $constraint = null)
 {
     // handle array packages
     if (is_array($candidate)) {
         $candidateName = $candidate['name'];
         $candidateVersion = $candidate['version'];
         $isDev = $candidate['stability'] === 'dev';
         $isAlias = isset($candidate['alias_of']);
     } else {
         // handle object packages
         $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 VersionConstraint('==', $candidateVersion);
         if ($constraint === null || $constraint->matches($pkgConstraint)) {
             return $requireFilter->matches($pkgConstraint) ? self::MATCH : self::MATCH_FILTERED;
         }
         return self::MATCH_NAME;
     }
     if (is_array($candidate)) {
         $provides = isset($candidate['provide']) ? $this->versionParser->parseLinks($candidateName, $candidateVersion, 'provides', $candidate['provide']) : array();
         $replaces = isset($candidate['replace']) ? $this->versionParser->parseLinks($candidateName, $candidateVersion, 'replaces', $candidate['replace']) : array();
     } else {
         $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;
 }
Esempio n. 2
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  LinkConstraintInterface $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, LinkConstraintInterface $constraint)
 {
     // handle array packages
     if (is_array($candidate)) {
         $candidateName = $candidate['name'];
         $candidateVersion = $candidate['version'];
     } else {
         // handle object packages
         $candidateName = $candidate->getName();
         $candidateVersion = $candidate->getVersion();
     }
     if ($candidateName === $name) {
         return $constraint->matches(new VersionConstraint('==', $candidateVersion)) ? self::MATCH : self::MATCH_NAME;
     }
     if (is_array($candidate)) {
         $provides = isset($candidate['provide']) ? $this->versionParser->parseLinks($candidateName, $candidateVersion, 'provides', $candidate['provide']) : array();
         $replaces = isset($candidate['replace']) ? $this->versionParser->parseLinks($candidateName, $candidateVersion, 'replaces', $candidate['replace']) : array();
     } else {
         $provides = $candidate->getProvides();
         $replaces = $candidate->getReplaces();
     }
     // aliases create multiple replaces/provides for one target so they can not use the shortcut
     if (isset($replaces[0]) || isset($provides[0])) {
         foreach ($provides as $link) {
             if ($link->getTarget() === $name && $constraint->matches($link->getConstraint())) {
                 return self::MATCH_PROVIDE;
             }
         }
         foreach ($replaces as $link) {
             if ($link->getTarget() === $name && $constraint->matches($link->getConstraint())) {
                 return self::MATCH_REPLACE;
             }
         }
         return self::MATCH_NONE;
     }
     if (isset($provides[$name]) && $constraint->matches($provides[$name]->getConstraint())) {
         return self::MATCH_PROVIDE;
     }
     if (isset($replaces[$name]) && $constraint->matches($replaces[$name]->getConstraint())) {
         return self::MATCH_REPLACE;
     }
     return self::MATCH_NONE;
 }
Esempio n. 3
0
 /**
  * Turns a constraint into text usable in a sentence describing a job
  *
  * @param  \Composer\Package\LinkConstraint\LinkConstraintInterface $constraint
  * @return string
  */
 protected function constraintToText($constraint)
 {
     return $constraint ? ' ' . $constraint->getPrettyString() : '';
 }
Esempio n. 4
0
 /**
  * @param PackageInterface $sourcePackage
  * @return string
  */
 public function getPrettyString(PackageInterface $sourcePackage)
 {
     return $sourcePackage->getPrettyString() . ' ' . $this->description . ' ' . $this->target . ' ' . $this->constraint->getPrettyString() . '';
 }
Esempio n. 5
0
 /**
  * Checks if the package matches the given constraint directly or through
  * provided or replaced packages
  *
  * @param  string                  $name       Name of the package to be matched
  * @param  LinkConstraintInterface $constraint The constraint to verify
  * @return bool                    Whether this package matches the name and constraint
  */
 public function matches($name, LinkConstraintInterface $constraint)
 {
     if ($this->name === $name) {
         return $constraint->matches(new VersionConstraint('==', $this->getVersion()));
     }
     foreach ($this->getProvides() as $link) {
         if ($link->getTarget() === $name && $constraint->matches($link->getConstraint())) {
             return true;
         }
     }
     foreach ($this->getReplaces() as $link) {
         if ($link->getTarget() === $name && $constraint->matches($link->getConstraint())) {
             return true;
         }
     }
     return false;
 }
Esempio n. 6
0
 /**
  * Checks if the package matches the given constraint directly or through
  * provided or replaced packages
  *
  * @param  string                  $name       Name of the package to be matched
  * @param  LinkConstraintInterface $constraint The constraint to verify
  * @return int                     One of the MATCH* constants of this class or 0 if there is no match
  */
 public function matches($name, LinkConstraintInterface $constraint)
 {
     if ($this->name === $name) {
         return $constraint->matches(new VersionConstraint('==', $this->getVersion())) ? self::MATCH : self::MATCH_NAME;
     }
     foreach ($this->getProvides() as $link) {
         if ($link->getTarget() === $name && $constraint->matches($link->getConstraint())) {
             return self::MATCH_PROVIDE;
         }
     }
     foreach ($this->getReplaces() as $link) {
         if ($link->getTarget() === $name && $constraint->matches($link->getConstraint())) {
             return self::MATCH_REPLACE;
         }
     }
     return self::MATCH_NONE;
 }
Esempio n. 7
0
File: Pool.php Progetto: VicDeo/poc
 private function match($candidate, $name, LinkConstraintInterface $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 VersionConstraint('==', $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();
     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;
 }