From d185194d1aedefd8c21d68afc60e88bd8949a863 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 23 Apr 2011 20:52:37 +0200 Subject: [PATCH] Create links/constraints between packages --- .../Repository/ComposerRepository.php | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index 21aedeed0..769747a58 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -14,6 +14,8 @@ namespace Composer\Repository; use Composer\Package\MemoryPackage; use Composer\Package\BasePackage; +use Composer\Package\Link; +use Composer\Package\LinkConstraint\VersionConstraint; /** * @author Jordi Boggiano @@ -52,25 +54,36 @@ class ComposerRepository extends ArrayRepository if (isset($rev['license'])) { $package->setLicense($rev['license']); } - //if (isset($rev['require'])) { - // $package->setRequires($rev['require']); - //} - //if (isset($rev['conflict'])) { - // $package->setConflicts($rev['conflict']); - //} - //if (isset($rev['provide'])) { - // $package->setProvides($rev['provide']); - //} - //if (isset($rev['replace'])) { - // $package->setReplaces($rev['replace']); - //} - //if (isset($rev['recommend'])) { - // $package->setRecommends($rev['recommend']); - //} - //if (isset($rev['suggest'])) { - // $package->setSuggests($rev['suggest']); - //} + + $links = array( + 'require', + 'conflict', + 'provide', + 'replace', + 'recommend', + 'suggest', + ); + foreach ($links as $link) { + if (isset($rev[$link])) { + $method = 'set'.$link.'s'; + $package->{$method}($this->createLinks($rev['name'], $link.'s', $rev[$link])); + } + } $this->addPackage($package); } } + + protected function createLinks($name, $description, $linkSpecs) + { + $links = array(); + foreach ($linkSpecs as $dep => $ver) { + preg_match('#^([>=<~]*)([\d.]+.*)$#', $ver, $match); + if (!$match[1]) { + $match[1] = '='; + } + $constraint = new VersionConstraint($match[1], $match[2]); + $links[] = new Link($name, $dep, $constraint, $description); + } + return $links; + } } \ No newline at end of file