Add package stability
parent
655588a5e0
commit
70a3c68f73
|
@ -28,6 +28,7 @@ class AliasPackage extends BasePackage
|
||||||
protected $dev;
|
protected $dev;
|
||||||
protected $aliasOf;
|
protected $aliasOf;
|
||||||
protected $rootPackageAlias = false;
|
protected $rootPackageAlias = false;
|
||||||
|
protected $stability;
|
||||||
|
|
||||||
protected $requires;
|
protected $requires;
|
||||||
protected $conflicts;
|
protected $conflicts;
|
||||||
|
@ -50,7 +51,8 @@ class AliasPackage extends BasePackage
|
||||||
$this->version = $version;
|
$this->version = $version;
|
||||||
$this->prettyVersion = $prettyVersion;
|
$this->prettyVersion = $prettyVersion;
|
||||||
$this->aliasOf = $aliasOf;
|
$this->aliasOf = $aliasOf;
|
||||||
$this->dev = VersionParser::isDev($version);
|
$this->stability = VersionParser::parseStability($version);
|
||||||
|
$this->dev = $this->stability === 'dev';
|
||||||
|
|
||||||
// replace self.version dependencies
|
// replace self.version dependencies
|
||||||
foreach (array('requires', 'devRequires') as $type) {
|
foreach (array('requires', 'devRequires') as $type) {
|
||||||
|
@ -91,6 +93,14 @@ class AliasPackage extends BasePackage
|
||||||
return $this->version;
|
return $this->version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function getStability()
|
||||||
|
{
|
||||||
|
return $this->stability;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -71,7 +71,8 @@ class MemoryPackage extends BasePackage
|
||||||
$this->version = $version;
|
$this->version = $version;
|
||||||
$this->prettyVersion = $prettyVersion;
|
$this->prettyVersion = $prettyVersion;
|
||||||
|
|
||||||
$this->dev = VersionParser::isDev($version);
|
$this->stability = VersionParser::parseStability($version);
|
||||||
|
$this->dev = $this->stability === 'dev';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -98,6 +99,14 @@ class MemoryPackage extends BasePackage
|
||||||
return $this->type ?: 'library';
|
return $this->type ?: 'library';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function getStability()
|
||||||
|
{
|
||||||
|
return $this->stability;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $targetDir
|
* @param string $targetDir
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -180,6 +180,13 @@ interface PackageInterface
|
||||||
*/
|
*/
|
||||||
function getPrettyVersion();
|
function getPrettyVersion();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the stability of this package: one of (dev, alpha, beta, RC, stable)
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function getStability();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the package license, e.g. MIT, BSD, GPL
|
* Returns the package license, e.g. MIT, BSD, GPL
|
||||||
*
|
*
|
||||||
|
|
|
@ -22,17 +22,30 @@ use Composer\Package\LinkConstraint\VersionConstraint;
|
||||||
*/
|
*/
|
||||||
class VersionParser
|
class VersionParser
|
||||||
{
|
{
|
||||||
private $modifierRegex = '[.-]?(?:(beta|RC|alpha|patch|pl|p)(?:[.-]?(\d+))?)?([.-]?dev)?';
|
private static $modifierRegex = '[.-]?(?:(beta|RC|alpha|patch|pl|p)(?:[.-]?(\d+))?)?([.-]?dev)?';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a version is dev or not
|
* Returns the stability of a version
|
||||||
*
|
*
|
||||||
* @param string $version
|
* @param string $version
|
||||||
* @return Boolean
|
* @return string
|
||||||
*/
|
*/
|
||||||
static public function isDev($version)
|
static public function parseStability($version)
|
||||||
{
|
{
|
||||||
return 'dev-' === substr($version, 0, 4) || '-dev' === substr($version, -4);
|
if ('dev-' === substr($version, 0, 4) || '-dev' === substr($version, -4)) {
|
||||||
|
return 'dev';
|
||||||
|
}
|
||||||
|
|
||||||
|
preg_match('{'.self::$modifierRegex.'$}', $version, $match);
|
||||||
|
if (!empty($match[3])) {
|
||||||
|
return 'dev';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($match[1]) && ($match[1] === 'beta' || $match[1] === 'alpha' || $match[1] === 'RC')) {
|
||||||
|
return $match[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'stable';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,13 +73,13 @@ class VersionParser
|
||||||
}
|
}
|
||||||
|
|
||||||
// match classical versioning
|
// match classical versioning
|
||||||
if (preg_match('{^v?(\d{1,3})(\.\d+)?(\.\d+)?(\.\d+)?'.$this->modifierRegex.'$}i', $version, $matches)) {
|
if (preg_match('{^v?(\d{1,3})(\.\d+)?(\.\d+)?(\.\d+)?'.self::$modifierRegex.'$}i', $version, $matches)) {
|
||||||
$version = $matches[1]
|
$version = $matches[1]
|
||||||
.(!empty($matches[2]) ? $matches[2] : '.0')
|
.(!empty($matches[2]) ? $matches[2] : '.0')
|
||||||
.(!empty($matches[3]) ? $matches[3] : '.0')
|
.(!empty($matches[3]) ? $matches[3] : '.0')
|
||||||
.(!empty($matches[4]) ? $matches[4] : '.0');
|
.(!empty($matches[4]) ? $matches[4] : '.0');
|
||||||
$index = 5;
|
$index = 5;
|
||||||
} elseif (preg_match('{^v?(\d{4}(?:[.:-]?\d{2}){1,6}(?:[.:-]?\d{1,3})?)'.$this->modifierRegex.'$}i', $version, $matches)) { // match date-based versioning
|
} elseif (preg_match('{^v?(\d{4}(?:[.:-]?\d{2}){1,6}(?:[.:-]?\d{1,3})?)'.self::$modifierRegex.'$}i', $version, $matches)) { // match date-based versioning
|
||||||
$version = preg_replace('{\D}', '-', $matches[1]);
|
$version = preg_replace('{\D}', '-', $matches[1]);
|
||||||
$index = 2;
|
$index = 2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,21 +195,25 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider dataIsDev
|
* @dataProvider stabilityProvider
|
||||||
*/
|
*/
|
||||||
public function testIsDev($expected, $version)
|
public function testParseStability($expected, $version)
|
||||||
{
|
{
|
||||||
$this->assertSame($expected, VersionParser::isDev($version));
|
$this->assertSame($expected, VersionParser::parseStability($version));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataIsDev()
|
public function stabilityProvider()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array(false, '1.0'),
|
array('stable', '1.0'),
|
||||||
array(false, 'v2.0.*'),
|
array('dev', 'v2.0.x-dev'),
|
||||||
array(false, '3.0dev'),
|
array('RC', '3.0-RC2'),
|
||||||
array(true, 'dev-master'),
|
array('dev', 'dev-master'),
|
||||||
array(true, '3.1.2-dev'),
|
array('dev', '3.1.2-dev'),
|
||||||
|
array('stable', '3.1.2-pl2'),
|
||||||
|
array('stable', '3.1.2-patch'),
|
||||||
|
array('alpha', '3.1.2-alpha5'),
|
||||||
|
array('beta', '3.1.2-beta'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue