PHP Semantic Versioning 2.0.0 utility library
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.gitignore
LICENSE
README.md
composer.json
composer.lock

README.md

SemverPHP

Semantic Versioning 2.0.0 utility library:

  • Comparison
  • Validation
  • Split

Installing / Running

composer require brunorb/semverphp
use BrunoRB\SemverPHP;

API

isValid(semver) -> bool

$v1 = '1.2.0-alpha+001';
$v2 = '1.2.1';
SemverPHP::isValid($v1); // true
SemverPHP::isValid($v2); // true
SemverPHP::isValid('1.1'); // false

split(semver) -> array

$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']

compare(semver1, semver2) -> int

$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

PATTERN -> string

preg_match(SemverPHP::PATTERN, 'semver');
preg_replace(SemverPHP::PATTERN, 'semver');
... other regex methods

Tests

tests/BasicTest.php

composer run-script test

License

The MIT License