From 46a67733f8cc1018741c2aad3c97edf8466f92b4 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 25 Sep 2011 23:58:50 +0200 Subject: [PATCH] Adjust codebase to the new VersionParser --- src/Composer/Package/BasePackage.php | 4 +-- src/Composer/Package/Dumper/ArrayDumper.php | 1 - .../LinkConstraint/VersionConstraint.php | 2 -- src/Composer/Package/Loader/ArrayLoader.php | 25 +++++++++++-------- src/Composer/Package/PackageInterface.php | 7 ------ src/Composer/Package/PackageLock.php | 4 +-- .../Repository/PlatformRepository.php | 12 ++++----- .../Test/Package/MemoryPackageTest.php | 5 ++-- .../Package/Version/VersionParserTest.php | 1 + .../Repository/FilesystemRepositoryTest.php | 2 +- 10 files changed, 29 insertions(+), 34 deletions(-) diff --git a/src/Composer/Package/BasePackage.php b/src/Composer/Package/BasePackage.php index 526e9e0ac..786c58ae5 100644 --- a/src/Composer/Package/BasePackage.php +++ b/src/Composer/Package/BasePackage.php @@ -103,7 +103,7 @@ abstract class BasePackage implements PackageInterface public function matches($name, LinkConstraintInterface $constraint) { if ($this->name === $name) { - return $constraint->matches(new VersionConstraint('==', $this->getVersion(), $this->getReleaseType())); + return $constraint->matches(new VersionConstraint('==', $this->getVersion())); } foreach ($this->getProvides() as $link) { @@ -141,7 +141,7 @@ abstract class BasePackage implements PackageInterface */ public function getUniqueName() { - return $this->getName().'-'.$this->getVersion().'-'.$this->getReleaseType(); + return $this->getName().'-'.$this->getVersion(); } /** diff --git a/src/Composer/Package/Dumper/ArrayDumper.php b/src/Composer/Package/Dumper/ArrayDumper.php index d13482264..123d0fa86 100644 --- a/src/Composer/Package/Dumper/ArrayDumper.php +++ b/src/Composer/Package/Dumper/ArrayDumper.php @@ -31,7 +31,6 @@ class ArrayDumper 'distType', 'distUrl', 'distSha1Checksum', - 'releaseType', 'version', 'license', 'requires', diff --git a/src/Composer/Package/LinkConstraint/VersionConstraint.php b/src/Composer/Package/LinkConstraint/VersionConstraint.php index c8ae4cb5b..2590aa3df 100644 --- a/src/Composer/Package/LinkConstraint/VersionConstraint.php +++ b/src/Composer/Package/LinkConstraint/VersionConstraint.php @@ -36,8 +36,6 @@ class VersionConstraint extends SpecificConstraint $operator = '=='; } - // TODO add third parameter releaseType and match that too - // TODO add fourth parameter devSnapshot and match that too $this->operator = $operator; $this->version = $version; } diff --git a/src/Composer/Package/Loader/ArrayLoader.php b/src/Composer/Package/Loader/ArrayLoader.php index 83a6e2051..69d67b5e3 100644 --- a/src/Composer/Package/Loader/ArrayLoader.php +++ b/src/Composer/Package/Loader/ArrayLoader.php @@ -16,6 +16,7 @@ use Composer\Package; /** * @author Konstantin Kudryashiv + * @author Jordi Boggiano */ class ArrayLoader { @@ -28,13 +29,22 @@ class ArrayLoader 'suggest' => 'suggests', ); + protected $versionParser; + + public function __construct($parser = null) + { + $this->versionParser = $parser; + if (!$parser) { + $this->versionParser = new Package\Version\VersionParser; + } + } + public function load($config) { $this->validateConfig($config); - $versionParser = new Package\Version\VersionParser(); - $version = $versionParser->parse($config['version']); - $package = new Package\MemoryPackage($config['name'], $version['version'], $version['type']); + $version = $this->versionParser->normalize($config['version']); + $package = new Package\MemoryPackage($config['name'], $version); $package->setType(isset($config['type']) ? $config['type'] : 'library'); @@ -87,15 +97,10 @@ class ArrayLoader private function loadLinksFromConfig($srcPackageName, $description, array $linksSpecs) { $links = array(); - foreach ($linksSpecs as $packageName => $version) { + foreach ($linksSpecs as $packageName => $constraint) { $name = strtolower($packageName); - preg_match('#^([>=<~]*)([\d.]+.*)$#', $version, $match); - if (!$match[1]) { - $match[1] = '='; - } - - $constraint = new Package\LinkConstraint\VersionConstraint($match[1], $match[2]); + $constraint = $this->versionParser->parseConstraints($constraint); $links[] = new Package\Link($srcPackageName, $packageName, $constraint, $description); } diff --git a/src/Composer/Package/PackageInterface.php b/src/Composer/Package/PackageInterface.php index e6e1fc19e..ed7c08bf4 100644 --- a/src/Composer/Package/PackageInterface.php +++ b/src/Composer/Package/PackageInterface.php @@ -131,13 +131,6 @@ interface PackageInterface */ function getDistSha1Checksum(); - /** - * Returns the release type of this package, e.g. stable or beta - * - * @return string The release type - */ - function getReleaseType(); - /** * Returns the version of this package * diff --git a/src/Composer/Package/PackageLock.php b/src/Composer/Package/PackageLock.php index 5e79cccce..e30ee3605 100644 --- a/src/Composer/Package/PackageLock.php +++ b/src/Composer/Package/PackageLock.php @@ -43,8 +43,8 @@ class PackageLock $versionParser = new VersionParser(); $packages = array(); foreach ($lockList as $info) { - $version = $versionParser->parse($info['version']); - $packages[] = new MemoryPackage($info['package'], $version['version'], $version['type']); + $version = $versionParser->normalize($info['version']); + $packages[] = new MemoryPackage($info['package'], $version); } return $packages; diff --git a/src/Composer/Repository/PlatformRepository.php b/src/Composer/Repository/PlatformRepository.php index a93e32bf0..64ae9bee4 100644 --- a/src/Composer/Repository/PlatformRepository.php +++ b/src/Composer/Repository/PlatformRepository.php @@ -36,12 +36,12 @@ class PlatformRepository extends ArrayRepository implements WritableRepositoryIn $versionParser = new VersionParser(); try { - $version = $versionParser->parse(PHP_VERSION); + $version = $versionParser->normalize(PHP_VERSION); } catch (\UnexpectedValueException $e) { - $version = $versionParser->parse(preg_replace('#^(.+?)(-.+)?$#', '$1', PHP_VERSION)); + $version = $versionParser->normalize(preg_replace('#^(.+?)(-.+)?$#', '$1', PHP_VERSION)); } - $php = new MemoryPackage('php', $version['version'], $version['type']); + $php = new MemoryPackage('php', $version); parent::addPackage($php); foreach (get_loaded_extensions() as $ext) { @@ -51,12 +51,12 @@ class PlatformRepository extends ArrayRepository implements WritableRepositoryIn $reflExt = new \ReflectionExtension($ext); try { - $version = $versionParser->parse($reflExt->getVersion()); + $version = $versionParser->normalize($reflExt->getVersion()); } catch (\UnexpectedValueException $e) { - $version = array('version' => '0', 'type' => 'stable'); + $version = '0.0.0'; } - $ext = new MemoryPackage('ext/'.strtolower($ext), $version['version'], $version['type']); + $ext = new MemoryPackage('ext/'.strtolower($ext), $version); parent::addPackage($ext); } } diff --git a/tests/Composer/Test/Package/MemoryPackageTest.php b/tests/Composer/Test/Package/MemoryPackageTest.php index 7176b8e4a..d61e97987 100644 --- a/tests/Composer/Test/Package/MemoryPackageTest.php +++ b/tests/Composer/Test/Package/MemoryPackageTest.php @@ -18,11 +18,10 @@ class MemoryPackageTest extends \PHPUnit_Framework_TestCase { public function testMemoryPackage() { - $package = new MemoryPackage('foo', '1', 'beta'); + $package = new MemoryPackage('foo', '1-beta'); $this->assertEquals('foo', $package->getName()); - $this->assertEquals('1', $package->getVersion()); - $this->assertEquals('beta', $package->getReleaseType()); + $this->assertEquals('1-beta', $package->getVersion()); $this->assertEquals('foo-1-beta', (string) $package); } diff --git a/tests/Composer/Test/Package/Version/VersionParserTest.php b/tests/Composer/Test/Package/Version/VersionParserTest.php index b35452a7f..25bd99341 100644 --- a/tests/Composer/Test/Package/Version/VersionParserTest.php +++ b/tests/Composer/Test/Package/Version/VersionParserTest.php @@ -34,6 +34,7 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase 'parses state' => array('1.0.0RC1dev', '1.0.0-rc1-dev'), 'CI parsing' => array('1.0.0-rC15-dev', '1.0.0-rc15-dev'), 'forces x.y.z' => array('1.0-dev', '1.0.0-dev'), + 'forces x.y.z' => array('0', '0.0.0'), 'parses long' => array('10.4.13-beta', '10.4.13-beta'), 'strips leading v' => array('v1.0.0', '1.0.0'), 'strips leading v' => array('v20100102', '20100102'), diff --git a/tests/Composer/Test/Repository/FilesystemRepositoryTest.php b/tests/Composer/Test/Repository/FilesystemRepositoryTest.php index ee777b52f..eda202302 100644 --- a/tests/Composer/Test/Repository/FilesystemRepositoryTest.php +++ b/tests/Composer/Test/Repository/FilesystemRepositoryTest.php @@ -49,7 +49,7 @@ class FilesystemRepositoryTest extends \PHPUnit_Framework_TestCase $data = json_decode(file_get_contents($this->repositoryFile), true); $this->assertEquals(array( - array('name' => 'package1', 'type' => 'vendor', 'version' => '1.0.0', 'releaseType' => 'beta', 'names' => array('package1')) + array('name' => 'package1', 'type' => 'vendor', 'version' => '1.0.0-beta', 'names' => array('package1')) ), $data); } }