Clean up link creation
parent
d6de4a0036
commit
9965f02951
|
@ -339,17 +339,12 @@ class Pool
|
||||||
if (is_array($candidate)) {
|
if (is_array($candidate)) {
|
||||||
$candidateName = $candidate['name'];
|
$candidateName = $candidate['name'];
|
||||||
$candidateVersion = $candidate['version'];
|
$candidateVersion = $candidate['version'];
|
||||||
foreach (array('provides', 'replaces') as $linkType) {
|
$provides = isset($candidate['provide'])
|
||||||
${$linkType} = isset($candidate[rtrim($linkType, 's')]) ? $candidate[rtrim($linkType, 's')] : array();
|
? $this->versionParser->parseLinks($candidateName, $candidateVersion, 'provides', $candidate['provide'])
|
||||||
foreach (${$linkType} as $target => $constraintDef) {
|
: array();
|
||||||
if ('self.version' === $constraintDef) {
|
$replaces = isset($candidate['replace'])
|
||||||
$parsedConstraint = $this->versionParser->parseConstraints($candidateVersion);
|
? $this->versionParser->parseLinks($candidateName, $candidateVersion, 'replaces', $candidate['replace'])
|
||||||
} else {
|
: array();
|
||||||
$parsedConstraint = $this->versionParser->parseConstraints($constraintDef);
|
|
||||||
}
|
|
||||||
${$linkType}[$target] = new Link($candidateName, $target, $parsedConstraint, $linkType, $constraintDef);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// handle object packages
|
// handle object packages
|
||||||
$candidateName = $candidate->getName();
|
$candidateName = $candidate->getName();
|
||||||
|
|
|
@ -107,7 +107,12 @@ class ArrayLoader implements LoaderInterface
|
||||||
if (isset($config[$type])) {
|
if (isset($config[$type])) {
|
||||||
$method = 'set'.ucfirst($opts['method']);
|
$method = 'set'.ucfirst($opts['method']);
|
||||||
$package->{$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;
|
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\BasePackage;
|
||||||
use Composer\Package\PackageInterface;
|
use Composer\Package\PackageInterface;
|
||||||
|
use Composer\Package\Link;
|
||||||
use Composer\Package\LinkConstraint\MultiConstraint;
|
use Composer\Package\LinkConstraint\MultiConstraint;
|
||||||
use Composer\Package\LinkConstraint\VersionConstraint;
|
use Composer\Package\LinkConstraint\VersionConstraint;
|
||||||
|
|
||||||
|
@ -164,6 +165,28 @@ class VersionParser
|
||||||
return 'dev-'.$name;
|
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
|
* Parses as constraint string into LinkConstraint objects
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue