Semantic Versioning 2.0.0 utility library:
- Comparison
- Validation
- Split
composer require brunorb/semverphp
use BrunoRB\SemverPHP;
$v1 = '1.2.0-alpha+001';
$v2 = '1.2.1';
SemverPHP::isValid($v1); // true
SemverPHP::isValid($v2); // true
SemverPHP::isValid('1.1'); // false
$v1 = '1.2.0-alpha+001';
$v2 = '1.2.1+001';
SemverPHP::split($v1); // [major: '1', minor: '2', patch: '0', preRelease: 'alpha', 'buildMetadata': '001']
SemverPHP::split($v2); // [major: '1', minor: '2', patch: '1', preRelease: null, buildMetadata: '001']
$v1 = '1.2.0-alpha+001';
$v2 = '1.2.1';
SemverPHP::compare($v1, $v2); // -1
SemverPHP::compare($v2, $v1); // 1
SemverPHP::compare($v1, $v1); // 0
preg_match(SemverPHP::PATTERN, 'semver');
preg_replace(SemverPHP::PATTERN, 'semver');
... other regex methods
composer run-script test