1
0
Fork 0

Adjust codebase to the new VersionParser

pull/21/head
Jordi Boggiano 2011-09-25 23:58:50 +02:00
parent f761cfe525
commit 46a67733f8
10 changed files with 29 additions and 34 deletions

View File

@ -103,7 +103,7 @@ abstract class BasePackage implements PackageInterface
public function matches($name, LinkConstraintInterface $constraint) public function matches($name, LinkConstraintInterface $constraint)
{ {
if ($this->name === $name) { 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) { foreach ($this->getProvides() as $link) {
@ -141,7 +141,7 @@ abstract class BasePackage implements PackageInterface
*/ */
public function getUniqueName() public function getUniqueName()
{ {
return $this->getName().'-'.$this->getVersion().'-'.$this->getReleaseType(); return $this->getName().'-'.$this->getVersion();
} }
/** /**

View File

@ -31,7 +31,6 @@ class ArrayDumper
'distType', 'distType',
'distUrl', 'distUrl',
'distSha1Checksum', 'distSha1Checksum',
'releaseType',
'version', 'version',
'license', 'license',
'requires', 'requires',

View File

@ -36,8 +36,6 @@ class VersionConstraint extends SpecificConstraint
$operator = '=='; $operator = '==';
} }
// TODO add third parameter releaseType and match that too
// TODO add fourth parameter devSnapshot and match that too
$this->operator = $operator; $this->operator = $operator;
$this->version = $version; $this->version = $version;
} }

View File

@ -16,6 +16,7 @@ use Composer\Package;
/** /**
* @author Konstantin Kudryashiv <ever.zet@gmail.com> * @author Konstantin Kudryashiv <ever.zet@gmail.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
*/ */
class ArrayLoader class ArrayLoader
{ {
@ -28,13 +29,22 @@ class ArrayLoader
'suggest' => 'suggests', 'suggest' => 'suggests',
); );
protected $versionParser;
public function __construct($parser = null)
{
$this->versionParser = $parser;
if (!$parser) {
$this->versionParser = new Package\Version\VersionParser;
}
}
public function load($config) public function load($config)
{ {
$this->validateConfig($config); $this->validateConfig($config);
$versionParser = new Package\Version\VersionParser(); $version = $this->versionParser->normalize($config['version']);
$version = $versionParser->parse($config['version']); $package = new Package\MemoryPackage($config['name'], $version);
$package = new Package\MemoryPackage($config['name'], $version['version'], $version['type']);
$package->setType(isset($config['type']) ? $config['type'] : 'library'); $package->setType(isset($config['type']) ? $config['type'] : 'library');
@ -87,15 +97,10 @@ class ArrayLoader
private function loadLinksFromConfig($srcPackageName, $description, array $linksSpecs) private function loadLinksFromConfig($srcPackageName, $description, array $linksSpecs)
{ {
$links = array(); $links = array();
foreach ($linksSpecs as $packageName => $version) { foreach ($linksSpecs as $packageName => $constraint) {
$name = strtolower($packageName); $name = strtolower($packageName);
preg_match('#^([>=<~]*)([\d.]+.*)$#', $version, $match); $constraint = $this->versionParser->parseConstraints($constraint);
if (!$match[1]) {
$match[1] = '=';
}
$constraint = new Package\LinkConstraint\VersionConstraint($match[1], $match[2]);
$links[] = new Package\Link($srcPackageName, $packageName, $constraint, $description); $links[] = new Package\Link($srcPackageName, $packageName, $constraint, $description);
} }

View File

@ -131,13 +131,6 @@ interface PackageInterface
*/ */
function getDistSha1Checksum(); 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 * Returns the version of this package
* *

View File

@ -43,8 +43,8 @@ class PackageLock
$versionParser = new VersionParser(); $versionParser = new VersionParser();
$packages = array(); $packages = array();
foreach ($lockList as $info) { foreach ($lockList as $info) {
$version = $versionParser->parse($info['version']); $version = $versionParser->normalize($info['version']);
$packages[] = new MemoryPackage($info['package'], $version['version'], $version['type']); $packages[] = new MemoryPackage($info['package'], $version);
} }
return $packages; return $packages;

View File

@ -36,12 +36,12 @@ class PlatformRepository extends ArrayRepository implements WritableRepositoryIn
$versionParser = new VersionParser(); $versionParser = new VersionParser();
try { try {
$version = $versionParser->parse(PHP_VERSION); $version = $versionParser->normalize(PHP_VERSION);
} catch (\UnexpectedValueException $e) { } 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); parent::addPackage($php);
foreach (get_loaded_extensions() as $ext) { foreach (get_loaded_extensions() as $ext) {
@ -51,12 +51,12 @@ class PlatformRepository extends ArrayRepository implements WritableRepositoryIn
$reflExt = new \ReflectionExtension($ext); $reflExt = new \ReflectionExtension($ext);
try { try {
$version = $versionParser->parse($reflExt->getVersion()); $version = $versionParser->normalize($reflExt->getVersion());
} catch (\UnexpectedValueException $e) { } 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); parent::addPackage($ext);
} }
} }

View File

@ -18,11 +18,10 @@ class MemoryPackageTest extends \PHPUnit_Framework_TestCase
{ {
public function testMemoryPackage() public function testMemoryPackage()
{ {
$package = new MemoryPackage('foo', '1', 'beta'); $package = new MemoryPackage('foo', '1-beta');
$this->assertEquals('foo', $package->getName()); $this->assertEquals('foo', $package->getName());
$this->assertEquals('1', $package->getVersion()); $this->assertEquals('1-beta', $package->getVersion());
$this->assertEquals('beta', $package->getReleaseType());
$this->assertEquals('foo-1-beta', (string) $package); $this->assertEquals('foo-1-beta', (string) $package);
} }

View File

@ -34,6 +34,7 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
'parses state' => array('1.0.0RC1dev', '1.0.0-rc1-dev'), 'parses state' => array('1.0.0RC1dev', '1.0.0-rc1-dev'),
'CI parsing' => array('1.0.0-rC15-dev', '1.0.0-rc15-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('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'), '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('v1.0.0', '1.0.0'),
'strips leading v' => array('v20100102', '20100102'), 'strips leading v' => array('v20100102', '20100102'),

View File

@ -49,7 +49,7 @@ class FilesystemRepositoryTest extends \PHPUnit_Framework_TestCase
$data = json_decode(file_get_contents($this->repositoryFile), true); $data = json_decode(file_get_contents($this->repositoryFile), true);
$this->assertEquals(array( $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); ), $data);
} }
} }