Clean up link creation
parent
d6de4a0036
commit
9965f02951
|
@ -339,17 +339,12 @@ class Pool
|
|||
if (is_array($candidate)) {
|
||||
$candidateName = $candidate['name'];
|
||||
$candidateVersion = $candidate['version'];
|
||||
foreach (array('provides', 'replaces') as $linkType) {
|
||||
${$linkType} = isset($candidate[rtrim($linkType, 's')]) ? $candidate[rtrim($linkType, 's')] : array();
|
||||
foreach (${$linkType} as $target => $constraintDef) {
|
||||
if ('self.version' === $constraintDef) {
|
||||
$parsedConstraint = $this->versionParser->parseConstraints($candidateVersion);
|
||||
} else {
|
||||
$parsedConstraint = $this->versionParser->parseConstraints($constraintDef);
|
||||
}
|
||||
${$linkType}[$target] = new Link($candidateName, $target, $parsedConstraint, $linkType, $constraintDef);
|
||||
}
|
||||
}
|
||||
$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 {
|
||||
// handle object packages
|
||||
$candidateName = $candidate->getName();
|
||||
|
|
|
@ -107,7 +107,12 @@ class ArrayLoader implements LoaderInterface
|
|||
if (isset($config[$type])) {
|
||||
$method = 'set'.ucfirst($opts['method']);
|
||||
$package->{$method}(
|
||||
$this->loadLinksFromConfig($package, $opts['description'], $config[$type])
|
||||
$this->versionParser->parseLinks(
|
||||
$package->getName(),
|
||||
$package->getPrettyVersion(),
|
||||
$opts['description'],
|
||||
$config[$type]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -209,19 +214,4 @@ class ArrayLoader implements LoaderInterface
|
|||
return $validatedTargetBranch;
|
||||
}
|
||||
}
|
||||
|
||||
private function loadLinksFromConfig($package, $description, array $linksSpecs)
|
||||
{
|
||||
$links = array();
|
||||
foreach ($linksSpecs as $packageName => $constraint) {
|
||||
if ('self.version' === $constraint) {
|
||||
$parsedConstraint = $this->versionParser->parseConstraints($package->getPrettyVersion());
|
||||
} else {
|
||||
$parsedConstraint = $this->versionParser->parseConstraints($constraint);
|
||||
}
|
||||
$links[] = new Package\Link($package->getName(), $packageName, $parsedConstraint, $description, $constraint);
|
||||
}
|
||||
|
||||
return $links;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace Composer\Package\Version;
|
|||
|
||||
use Composer\Package\BasePackage;
|
||||
use Composer\Package\PackageInterface;
|
||||
use Composer\Package\Link;
|
||||
use Composer\Package\LinkConstraint\MultiConstraint;
|
||||
use Composer\Package\LinkConstraint\VersionConstraint;
|
||||
|
||||
|
@ -164,6 +165,28 @@ class VersionParser
|
|||
return 'dev-'.$name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $source source package name
|
||||
* @param string $sourceVersion source package version (pretty version ideally)
|
||||
* @param string $description link description (e.g. requires, replaces, ..)
|
||||
* @param array $links array of package name => constraint mappings
|
||||
* @return Link[]
|
||||
*/
|
||||
public function parseLinks($source, $sourceVersion, $description, $links)
|
||||
{
|
||||
$res = array();
|
||||
foreach ($links as $target => $constraint) {
|
||||
if ('self.version' === $constraint) {
|
||||
$parsedConstraint = $this->parseConstraints($sourceVersion);
|
||||
} else {
|
||||
$parsedConstraint = $this->parseConstraints($constraint);
|
||||
}
|
||||
$res[] = new Link($source, $target, $parsedConstraint, $description, $constraint);
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses as constraint string into LinkConstraint objects
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue