Library for parsing and manipulating Semantic Versioning ("SemVer") relases

dev-develop 2020-12-30 03:02 UTC

This package is auto-updated.

Last update: 2021-12-29 03:29:53 UTC


Build Status

This library defines the SteveGrunwell\SemVer\Version class, which is meant to parse and manipulate version numbers based on the rules of Semantic Versioning (a.k.a. "SemVer").


Install the library using Composer:

$ composer require stevegrunwell/semver-parser


The constructor of the Version class can accept a valid, semantic version based on the Semantic Versioning 2.0.0 specification:

use SteveGrunwell\SemVer\Parser;

// Import the Composer-generated autoloader.
require_once __DIR__ . '/vendor/autoload.php';

$version = new Version('1.2.3-rc1');

// Parse the version.
$version->getMajorVersion();      // 1
$version->getMinorVersion();      // 2
$version->getPatchVersion();      // 3
$version->getPreReleaseVersion(); // rc1

// Modify the version.

// Retrieve the updated version as a string.
$version->getVersion(); // "4.5.6-rc2"
(string) $version;      // "4.5.6-rc2"

Additional methods

In addition to the setters and getters described above, each of the major, minor, and patch values have corresponding increment and decrement methods:

// Increment values.

// Decrement values.

It's worth noting that incrementMajorVersion() and incrementMinorVersion() will reset the the minor/patch and patch numbers (respectively) according to the Semantic Versioning 2.0.0 specification.


This library is released under the MIT License. Please see for more details.