1
0
Fork 0

Clean up link creation

pull/1015/head
Jordi Boggiano 2012-08-23 16:12:46 +02:00
parent d6de4a0036
commit 9965f02951
3 changed files with 35 additions and 27 deletions

View File

@ -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();

View File

@ -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;
}
}

View File

@ -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
*