|
|
1 yıl önce | |
|---|---|---|
| .. | ||
| .github | 1 yıl önce | |
| bin | 1 yıl önce | |
| src | 1 yıl önce | |
| tests | 1 yıl önce | |
| .gitignore | 1 yıl önce | |
| README.md | 1 yıl önce | |
| composer.json | 1 yıl önce | |
| definitions | 1 yıl önce | |
| license.md | 1 yıl önce | |
| phpunit.xml | 1 yıl önce | |
Ported from node-semver 1.1.2 to PHP
<?php
use vierbergenlars\SemVer\version;
use vierbergenlars\SemVer\expression;
use vierbergenlars\SemVer\SemVerException;
// Check if a version is valid
$semver = new version('1.2.3');
$semver = new version('a.b.c'); //SemVerException thrown
//Get a clean version string
$semver = new version('=v1.2.3');
$semver->getVersion(); //'1.2.3'
//Check if a version satisfies a range
$semver = new version('1.2.3');
$semver->satisfies(new expression('1.x || >=2.5.0 || 5.0.0 - 7.2.3')); //true
# OR
$range = new expression('1.x || >=2.5.0 || 5.0.0 - 7.2.3');
$range->satisfiedBy(new version('1.2.3')); //true
//Compare two versions
version::gt('1.2.3', '9.8.7'); //false
version::lt('1.2.3', '9.8.7'); //true
A version is the following things, in this order:
A leading "=" or "v" character is stripped off and ignored.
The ordering of versions is done using the following algorithm, given two versions and asked to find the greater of the two:
2.3.4 > 1.3.42.3.4 > 2.2.42.3.4 > 2.3.32.3.4-0 > 2.3.42.3.4-10 > 2.3.4-92.3.4 > 2.3.4-beta2.3.4-beta > 2.3.4-alphaThe following range styles are supported:
>1.2.3 Greater than a specific version.<1.2.3 Less than1.2.3 - 2.3.4 := >=1.2.3 <=2.3.4~1.2.3 := >=1.2.3 <1.3.0~1.2 := >=1.2.0 <2.0.0~1 := >=1.0.0 <2.0.01.2.x := >=1.2.0 <1.3.01.x := >=1.0.0 <2.0.0Ranges can be joined with either a space (which implies "and") or a
|| (which implies "or").
$version->valid(): Return the parsed version, or null if it's not valid.$version->inc($type): Return the version incremented by the release type
(major, minor, patch, or build), or null if an invalid release type is provided.version::gt($v1, $v2): v1 > v2version::gte($v1, $v2): v1 >= v2version::lt($v1, $v2): v1 < v2version::lte($v1, $v2): v1 <= v2version::eq($v1, $v2): v1 == v2 This is true if they're logically equivalent,
even if they're not the exact same string. You already know how to
compare strings.version::neq($v1, $v2): v1 != v2 The opposite of eq.version::cmp($v1, $comparator, $v2): Pass in a comparison string, and it'll call
the corresponding function above. "===" and "!==" do simple
string comparison, but are included for completeness. Throws if an
invalid comparison string is provided.version::compare($v1, $v2): Return 0 if v1 == v2, 1 if v1 > v2, or -1 if
v1 < v2. Sorts in ascending order if passed to usort()version::rcompare($v1, $v2): The reverse of compare. Sorts an array of versions
in descending order when passed to usort().$expression->validRange(): Return the valid range or null if it's not valid$version->satisfies($range): Return true if the version satisfies the range.$expression->maxSatisfying($versions): Return the highest version in the array
that satisfies the range, or null if none of them do.All contributors (https://github.com/vierbergenlars/php-semver/graphs/contributors)
@isaacs and other contributors to node-semver