1
0
Fork 0

Added isDev method to the VersionParser class

pull/381/head
Martin Hasoň 2012-03-03 14:07:13 +01:00
parent 3abfa00b11
commit 736ea800e3
4 changed files with 36 additions and 3 deletions

View File

@ -16,6 +16,7 @@ use Composer\Package\LinkConstraint\LinkConstraintInterface;
use Composer\Package\LinkConstraint\VersionConstraint; use Composer\Package\LinkConstraint\VersionConstraint;
use Composer\Repository\RepositoryInterface; use Composer\Repository\RepositoryInterface;
use Composer\Repository\PlatformRepository; use Composer\Repository\PlatformRepository;
use Composer\Package\Version\VersionParser;
/** /**
* @author Jordi Boggiano <j.boggiano@seld.be> * @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 $version The version the alias must report
* @param string $prettyVersion The alias's non-normalized version * @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()); parent::__construct($aliasOf->getName());
$this->version = $version; $this->version = $version;
$this->prettyVersion = $prettyVersion; $this->prettyVersion = $prettyVersion;
$this->aliasOf = $aliasOf; $this->aliasOf = $aliasOf;
$this->dev = 'dev-' === substr($version, 0, 4) || '-dev' === substr($version, -4); $this->dev = VersionParser::isDev($version);
// replace self.version dependencies // replace self.version dependencies
foreach (array('requires', 'recommends', 'suggests') as $type) { foreach (array('requires', 'recommends', 'suggests') as $type) {

View File

@ -12,6 +12,8 @@
namespace Composer\Package; namespace Composer\Package;
use Composer\Package\Version\VersionParser;
/** /**
* A package with setters for all members to create it dynamically in memory * 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->version = $version;
$this->prettyVersion = $prettyVersion; $this->prettyVersion = $prettyVersion;
$this->dev = 'dev-' === substr($version, 0, 4) || '-dev' === substr($version, -4); $this->dev = VersionParser::isDev($version);
} }
/** /**

View File

@ -24,6 +24,17 @@ class VersionParser
{ {
private $modifierRegex = '[.-]?(?:(beta|RC|alpha|patch|pl|p)(?:[.-]?(\d+))?)?([.-]?dev)?'; 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 * Normalizes a version string to be able to perform comparisons on it
* *

View File

@ -187,4 +187,23 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
'invalid version' => array('1.0.0-meh'), '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'),
);
}
} }