2017 © Pedro Peláez
 

library semver

A decent, standards-compliant, Semantic Versioning (SemVer) parser and library

image

naneau/semver

A decent, standards-compliant, Semantic Versioning (SemVer) parser and library

  • Friday, January 4, 2013
  • by naneau
  • Repository
  • 2 Watchers
  • 69 Stars
  • 31,900 Installations
  • PHP
  • 9 Dependents
  • 0 Suggesters
  • 10 Forks
  • 12 Open issues
  • 6 Versions
  • 11 % Grown

The README.md

A decent SemVer library

Build Status SensioLabsInsight Scrutinizer Quality Score Code Coverage, (*1)

This library is a SemVer parser written in PHP. It has a solid, fully tested OO API that makes it easy to work with SemVer versions., (*2)

This library was born out of a lack of decent tools to read and manipulate SemVer versions in PHP. The libraries currently out there are either not fully standards compatible, and/or lack a decent API., (*3)

Usage (PHP)

Parsing and Properties

Parsing strings into SemVer Versions is easy:, (*4)

<?php

use Naneau\SemVer\Parser;

// Parse a SemVer string
$version = Parser::parse('1.2.3-alpha.1+build.12345.ea4f51');

// Root parts
echo $version->getMajor(); // => 1
echo $version->getMinor(); // => 2
echo $version->getPatch(); // => 3

// Pre-release part ('-alpha.1')
if ($version->hasPreRelease()) {
    echo $version->getPreRelease()->getGreek(); // => alpha
    echo $version->getPreRelease()->getReleaseNumber(); // => 1
    echo $version->getPreRelease() // => alpha.1
}

// Build part ('+build.12345')
if ($version->hasBuild()) {
    echo $version->getBuild()->getNumber(); // => 12345
    var_dump($version->getBuild()->getParts()); // => array(0 => 'ea4f51');
}

// Full version echo
echo $version; // => 1.2.3-alpha.1+build.12345.ea4f51

Comparison

Comparing two versions is easy:, (*5)

<?php

use Naneau\SemVer\Parser;
use Naneau\SemVer\Compare;

Compare::greaterThan(
    Parser::parse('1.2.1-beta'),
    Parser::parse('1.2.1-alpha.1')
); // ==> true

Compare::equals(
    Parser::parse('1.2.1-beta'),
    Parser::parse('1.2.1-alpha.1')
); // ==> false

Compare::smallerThan(
    Parser::parse('1.2.0'),
    Parser::parse('1.2.1')
); // ==> true

Sorting

There is a built in sorting method, that takes an arbitrary number of arguments (either strings or Version instances) and returns an array, sorted in descending order of SemVer:, (*6)

<?php

use Naneau\SemVer\Sort;

$sorted = Sort::sort('1.2.1-beta', '1.2.0+build.10', '0.9.29');

echo $sorted[0]; // => 0.9.29
echo $sorted[1]; // => 1.2.0+build.10
echo $sorted[2]; // => 1.2.1-beta

The Versions

04/01 2013

dev-master

9999999-dev https://github.com/naneau/semver

A decent, standards-compliant, Semantic Versioning (SemVer) parser and library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

semantic versioning semver

04/01 2013

dev-get_original_version

dev-get_original_version https://github.com/naneau/semver

A decent, standards-compliant, Semantic Versioning (SemVer) parser and library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

semantic versioning semver

04/01 2013

dev-travis

dev-travis https://github.com/naneau/semver

A decent, standards-compliant, Semantic Versioning (SemVer) parser and library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

semantic versioning semver

04/01 2013

0.0.5

0.0.5.0 https://github.com/naneau/semver

A decent, standards-compliant, Semantic Versioning (SemVer) parser and library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

semantic versioning semver

04/01 2013

0.0.6

0.0.6.0 https://github.com/naneau/semver

A decent, standards-compliant, Semantic Versioning (SemVer) parser and library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

semantic versioning semver

04/01 2013

0.0.7

0.0.7.0 https://github.com/naneau/semver

A decent, standards-compliant, Semantic Versioning (SemVer) parser and library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

semantic versioning semver