Merge pull request #381 from hason/version
Added isDev method to the VersionParser classpull/384/head
commit
6de46a16e6
|
@ -16,6 +16,7 @@ use Composer\Package\LinkConstraint\LinkConstraintInterface;
|
|||
use Composer\Package\LinkConstraint\VersionConstraint;
|
||||
use Composer\Repository\RepositoryInterface;
|
||||
use Composer\Repository\PlatformRepository;
|
||||
use Composer\Package\Version\VersionParser;
|
||||
|
||||
/**
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
|
@ -41,14 +42,14 @@ class AliasPackage extends BasePackage
|
|||
* @param string $version The version the alias must report
|
||||
* @param string $prettyVersion The alias's non-normalized version
|
||||
*/
|
||||
public function __construct($aliasOf, $version, $prettyVersion)
|
||||
public function __construct(PackageInterface $aliasOf, $version, $prettyVersion)
|
||||
{
|
||||
parent::__construct($aliasOf->getName());
|
||||
|
||||
$this->version = $version;
|
||||
$this->prettyVersion = $prettyVersion;
|
||||
$this->aliasOf = $aliasOf;
|
||||
$this->dev = 'dev-' === substr($version, 0, 4) || '-dev' === substr($version, -4);
|
||||
$this->dev = VersionParser::isDev($version);
|
||||
|
||||
// replace self.version dependencies
|
||||
foreach (array('requires', 'recommends', 'suggests') as $type) {
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
|
||||
namespace Composer\Package;
|
||||
|
||||
use Composer\Package\Version\VersionParser;
|
||||
|
||||
/**
|
||||
* A package with setters for all members to create it dynamically in memory
|
||||
*
|
||||
|
@ -69,7 +71,7 @@ class MemoryPackage extends BasePackage
|
|||
$this->version = $version;
|
||||
$this->prettyVersion = $prettyVersion;
|
||||
|
||||
$this->dev = 'dev-' === substr($version, 0, 4) || '-dev' === substr($version, -4);
|
||||
$this->dev = VersionParser::isDev($version);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,6 +24,17 @@ class VersionParser
|
|||
{
|
||||
private $modifierRegex = '[.-]?(?:(beta|RC|alpha|patch|pl|p)(?:[.-]?(\d+))?)?([.-]?dev)?';
|
||||
|
||||
/**
|
||||
* Checks if a version is dev or not
|
||||
*
|
||||
* @param string $version
|
||||
* @return Boolean
|
||||
*/
|
||||
static public function isDev($version)
|
||||
{
|
||||
return 'dev-' === substr($version, 0, 4) || '-dev' === substr($version, -4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes a version string to be able to perform comparisons on it
|
||||
*
|
||||
|
|
|
@ -187,4 +187,23 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
|
|||
'invalid version' => array('1.0.0-meh'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataIsDev
|
||||
*/
|
||||
public function testIsDev($expected, $version)
|
||||
{
|
||||
$this->assertSame($expected, VersionParser::isDev($version));
|
||||
}
|
||||
|
||||
public function dataIsDev()
|
||||
{
|
||||
return array(
|
||||
array(false, '1.0'),
|
||||
array(false, 'v2.0.*'),
|
||||
array(false, '3.0dev'),
|
||||
array(true, 'dev-master'),
|
||||
array(true, '3.1.2-dev'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue