-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ae83c73
Showing
13 changed files
with
823 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/vendor/ | ||
|
||
/composer.lock | ||
/*.iml | ||
|
||
# IDE files | ||
/.idea/ | ||
|
||
# Eclipse files | ||
*.pydevproject | ||
.metadata | ||
.gradle | ||
/tmp/ | ||
*.tmp | ||
*.bak | ||
*.swp | ||
*~.nib | ||
local.properties | ||
.settings/ | ||
.loadpath | ||
|
||
# External tool builders | ||
.externalToolBuilders/ | ||
|
||
# Locally stored "Eclipse launch configurations" | ||
*.launch | ||
|
||
# CDT-specific | ||
.cproject | ||
|
||
# PDT-specific | ||
.buildpath | ||
|
||
# sbteclipse plugin | ||
.target | ||
|
||
# TeXlipse plugin | ||
.texlipse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Version Helper for PHP projects | ||
=============================== | ||
|
||
This module normalize versions as Composer do. Parse constraints as Composer do too. | ||
And tests if a version match a constraint. | ||
|
||
Example: | ||
|
||
```php | ||
<?php | ||
|
||
$parser = new \Version\VersionParser(); | ||
|
||
echo $parser->parseStability('1.2-RC2'); // RC | ||
echo $parser->parseStability('2.0b'); // beta | ||
echo $parser->parseConstraints('1.0'); // stable | ||
|
||
echo $parser->normalize('2.0b1'); // 2.0.0.0-beta1 | ||
|
||
$c = $parser->parseConstraints('>=1.2.5,<2.0'); | ||
echo $c->match('1.2.0'); // false | ||
echo $c->match('1.5'); // true | ||
echo $c->match('2.0'); // false | ||
?> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "version/version", | ||
"description": "A library for creating, editing, and comparing semantic versioning numbers.", | ||
"keywords": ["semantic", "version"], | ||
"homepage": "http://github.com/php-mod/version", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Hassan Amouhzi", | ||
"email": "[email protected]", | ||
"homepage": "http://anezi.net" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.3.3" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "4.3.*" | ||
}, | ||
"autoload": { | ||
"psr-0": { | ||
"Version": "src/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="true" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
stopOnError="false" | ||
stopOnFailure="false" | ||
stopOnIncomplete="false" | ||
stopOnSkipped="false" | ||
strict="true" | ||
verbose="false"> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src/</directory> | ||
</whitelist> | ||
</filter> | ||
<testsuites> | ||
<testsuite name="Version Test Suite"> | ||
<directory phpVersion="5.3.0" | ||
phpVersionOperator=">=" | ||
suffix="Test.php">tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Version\Constraint; | ||
|
||
abstract class AbstractConstraint | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Version\Constraint; | ||
|
||
class EmptyConstraint extends AbstractConstraint | ||
{ | ||
public function __toString() | ||
{ | ||
return '*'; | ||
} | ||
|
||
public function match() | ||
{ | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Version\Constraint; | ||
|
||
class MultiConstraint | ||
{ | ||
public function __construct(array $minMax, $and = true) | ||
{ | ||
$this->minMax = $minMax; | ||
$this->and = $and; | ||
} | ||
|
||
public function __toString() | ||
{ | ||
return implode($this->and ? ',' : '|', $this->minMax); | ||
} | ||
|
||
public function match($version) | ||
{ | ||
if($this->and) { | ||
foreach($this->minMax as $c) { | ||
if(!$c->match($version)) | ||
return false; | ||
} | ||
return true; | ||
} else { | ||
foreach($this->minMax as $c) { | ||
if($c->match($version)) | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Version\Constraint; | ||
|
||
use Version\VersionParser; | ||
|
||
class VersionConstraint extends AbstractConstraint | ||
{ | ||
private $operator; | ||
private $version; | ||
|
||
public function __construct($operator, $version) | ||
{ | ||
$this->operator = $operator; | ||
if(!is_string($version)) { | ||
throw new \InvalidArgumentException('Arg 2 must be a string'); | ||
} | ||
$this->version = $version; | ||
} | ||
|
||
public function __toString() | ||
{ | ||
return $this->operator . | ||
$this->version; | ||
} | ||
|
||
public function match($version) | ||
{ | ||
$parser = new VersionParser(); | ||
$version = $parser->normalize($version); | ||
return version_compare($version, $parser->normalize($this->version), $this->operator); | ||
} | ||
} |
Oops, something went wrong.