ceus-media/semantic-versioning

0.2.0 2024-02-25 04:07 UTC

This package is auto-updated.

Last update: 2024-04-25 04:31:29 UTC


README

Branch Release PHP version PHPStan level

Simple (and by now incomplete) implementation of Semantic Versioning for PHP 8.

Installation

composer require ceus-media/semantic-versioning

Usage

Create a version and manipulate:

$v = new Version( '1.2.3' );
$v->incrementPatch();  //  --> 1.2.4
$v->incrementMinor();  //  --> 1.3.0
$v->incrementMajor();  //  --> 2.0.0

Compare versions:

$v1 = new Version( '1.2.3' );
$v2 = new Version( '1.2.4' );
$v2->isLowerThan( $v1 );      //  -->  no
$v2->isGreaterThan( $v1 );    //  -->  yes
$v2->isAtLeast( $v1 );        //  -->  yes
$v2->isAtMost( $v1 );         //  -->  no
$v2->isEqualTo( $v1 );        //  -->  no
$v2->isDifferentFrom( $v1 );  //  -->  yes

Define ranges and compare :

$r	= new Range( '^1.2' );
Renderer::render( $r );      //  -> '^1.2.0
$r->checkVersion( '1.0.0' )  //  --> n;
$r->checkVersion( '1.1.0' )  //  --> n;
$r->checkVersion( '1.2.0' )  //  --> y;
$r->checkVersion( '1.3.0' )  //  --> n;
$r->checkVersion( '2.0.0' )  //  --> n;

Constraints:

... to be documented