Skip to content

BrunoRB/semverphp

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 

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

About

PHP Semantic Versioning 2.0.0 utility library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages