2017 © Pedro Peláez
 

library semantic-versioning

A tiny independent library for parsing and comparing semantic versions.

image

rayne/semantic-versioning

A tiny independent library for parsing and comparing semantic versions.

  • Friday, December 29, 2017
  • by Rayne
  • Repository
  • 2 Watchers
  • 1 Stars
  • 63 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 2 % Grown

The README.md

Rayne\SemanticVersioning

A tiny independent library for parsing and comparing semantic versions which is compatible with Semantic Versioning 2.0., (*1)

Latest Stable Version Latest Unstable Version Build Status Code Coverage Scrutinizer Code Quality License, (*2)

Dependencies

Production

  • PHP 5.6 or better

Development

  • Composer
  • Git
  • PHPUnit

Setup

Download Composer and install rayne/semantic-versioning., (*3)

composer require rayne/semantic-versioning

Tests

  1. Clone the repository, (*4)

    git clone https://github.com/rayne/semantic-versioning.php.git
  2. Install the development dependencies, (*5)

    composer install --dev
  3. Run the tests, (*6)

    ./vendor/bin/phpunit

Examples

The library contains the following classes:, (*7)

  • InvalidVersionException: Thrown by SemanticVersion on invalid input, (*8)

  • SemanticComparator: The semantic versioning comparator for comparing SemanticVersion objects, (*9)

  • SemanticVersion: The semantic versioning parser which throws a RuntimeException on invalid versions, (*10)

The examples are part of the test suite. Have a look at the tests directory for more information., (*11)

Interpret semantic versions

use Rayne\SemanticVersioning\SemanticVersion;

$version = new SemanticVersion('1.0.0-beta+exp.sha.5114f85');

assert('1.0.0-beta+exp.sha.5114f85' === (string) $version);
assert( 1                           === $version->getMajor());
assert(   0                         === $version->getMinor());
assert(     0                       === $version->getPatch());
assert(      'beta'                 === $version->getPre());
assert(           'exp.sha.5114f85' === $version->getMeta());
assert('1.0.0-beta+exp.sha.5114f85' === $version->getVersion());

assert(true  === $version->isMajorRelease());
assert(false === $version->isMinorRelease());
assert(false === $version->isPatchRelease());
assert(true  === $version->isPreRelease());

Compare semantic versions

use Rayne\SemanticVersioning\SemanticComparator;
use Rayne\SemanticVersioning\SemanticVersion;

$comparator     = new SemanticComparator;

$alpha          = new SemanticVersion('1.0.0-alpha');
$candidate      = new SemanticVersion('1.0.0-rc.1');
$candidate_meta = new SemanticVersion('1.0.0-rc.1+ci');
$release        = new SemanticVersion('1.0.0');

// $alpha < $candidate
assert($comparator($alpha, $candidate) < 0);
assert($comparator->compare($alpha, $candidate) < 0);

// $candidate == $candidate_meta
assert($comparator($candidate, $candidate_meta) == 0);
assert($comparator->compare($candidate, $candidate_meta) == 0);

// $release > $candidate
assert($comparator($release, $candidate) > 0);
assert($comparator->compare($release, $candidate) > 0);

Sort semantic versions

use Rayne\SemanticVersioning\SemanticComparator;
use Rayne\SemanticVersioning\SemanticVersion;

$versions = [
    $candidate = new SemanticVersion('1.0.0-rc.1'),
    $release   = new SemanticVersion('1.0.0'),
    $alpha     = new SemanticVersion('1.0.0-alpha'),
];

// Sort by semantic precedence.
usort($versions, new SemanticComparator);

assert($versions[0] === $alpha);
assert($versions[1] === $candidate);
assert($versions[2] === $release);

The Versions

29/12 2017

dev-master

9999999-dev

A tiny independent library for parsing and comparing semantic versions.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Dennis Meckel

semantic versioning semver

29/12 2017

dev-dev

dev-dev

A tiny independent library for parsing and comparing semantic versions.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Dennis Meckel

semantic versioning semver

13/02 2017

1.1.0

1.1.0.0

A tiny independent library for parsing and comparing semantic versions.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Dennis Meckel

semantic versioning semver

24/07 2016

1.0.0

1.0.0.0

A tiny independent library for parsing and comparing semantic versions.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Dennis Meckel

semantic versioning semver

23/07 2016

dev-child-process-for-class-loader-testing

dev-child-process-for-class-loader-testing

A tiny independent library for parsing and comparing semantic versions.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Dennis Meckel

semantic versioning semver

22/07 2016

1.0.0-rc.3

1.0.0.0-RC3

A tiny independent library for parsing and comparing semantic versions.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Dennis Meckel

semantic versioning semver

23/12 2015

1.0.0-rc.2

1.0.0.0-RC2

A tiny independent library for parsing and comparing semantic versions.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Dennis Meckel

semantic versioning semver

22/12 2015

1.0.0-rc.1

1.0.0.0-RC1

A tiny independent library for parsing and comparing semantic versions.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Dennis Meckel

semantic versioning semver