fractal/semver

The package helps to work with semantic versions.

v1.0.1 2019-09-25 11:23 UTC

This package is auto-updated.

Last update: 2024-04-25 21:53:53 UTC


README

Coverage and Quality:

Coverage Status Code Coverage Scrutinizer Code Quality Code Intelligence Status codecov.io

Build:

Build Status Build Status

Other:

Latest Stable Version Total Downloads License

Features

  • Simple package for semantic version manipulation.
  • Compare semantic version.
  • Validates semantic version.
  • Throws exceptions if Versions are not instance of each other.

Usage

Fractal\SemVer\SemanticVersion class:

<?php
    
use Fractal\SemVer\SemanticVersion;
    
## Create instance of SemVer
## If SemVer not valid, throws \Fractal\SemVer\Exceptions\ParseVersionException
$version = SemanticVersion::fromString('1.0.0'); # \Fractal\SemVer\Contracts\VersionInterface
$other = SemanticVersion::fromString('0.1.0'); # \Fractal\SemVer\Contracts\VersionInterface

## Version can compare each other
## If compare operator not valid, throws \Fractal\SemVer\Exceptions\InvalidOperatorException
## If version and other version are not instance of each other, throws \Fractal\SemVer\Exceptions\VersionClassNotEqualException
$version->eq($other); # false
$version->gte($other); # true

Fractal\SemVer\Comparator class:

<?php
    
use Fractal\SemVer\SemanticVersion;
use Fractal\SemVer\Comparator;
    
## Create instance of SemVer
## If SemVer not valid, throws \Fractal\SemVer\Exceptions\ParseVersionException
$version = SemanticVersion::fromString('1.0.0'); # \Fractal\SemVer\Contracts\VersionInterface
$other = SemanticVersion::fromString('0.1.0'); # \Fractal\SemVer\Contracts\VersionInterface

## Compare versions with comparator
## If compare operator not valid, throws \Fractal\SemVer\Exceptions\InvalidOperatorException
## If version and other version are not instance of each other, throws \Fractal\SemVer\Exceptions\VersionClassNotEqualException
Comparator::eq($version, $other); # false
Comparator::gte($version, $other); # true

License

The SemVer package is open-sourced software licensed under the MIT license.