ergebnis / version
Provides an abstraction of a semantic version.
Installs: 4 338
Dependents: 0
Suggesters: 0
Security: 0
Stars: 18
Watchers: 3
Forks: 1
Open Issues: 1
Requires
- php: ~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0
Requires (Dev)
- ext-bcmath: *
- ergebnis/composer-normalize: ^2.44.0
- ergebnis/data-provider: ^3.3.0
- ergebnis/license: ^2.6.0
- ergebnis/php-cs-fixer-config: ^6.37.0
- ergebnis/phpunit-slow-test-detector: ^2.16.1
- fakerphp/faker: ^1.24.0
- infection/infection: ~0.26.6
- phpstan/extension-installer: ^1.4.3
- phpstan/phpstan: ^1.12.10
- phpstan/phpstan-deprecation-rules: ^1.2.1
- phpstan/phpstan-phpunit: ^1.4.0
- phpstan/phpstan-strict-rules: ^1.6.1
- phpunit/phpunit: ^9.6.20
- rector/rector: ^1.2.10
Suggests
- ext-bcmath: If you want to bump Major, Minor, or Patch versions greater than PHP_MAX_INT.
This package is auto-updated.
Last update: 2024-12-09 21:40:28 UTC
README
This project provides a composer
package with an abstraction of a semantic version.
Installation
Run
composer require ergebnis/version
Usage
This project comes with the following components:
Ergebnis\Version\Version
Ergebnis\Version\Major
Ergebnis\Version\Minor
Ergebnis\Version\Patch
Ergebnis\Version\PreRelease
Ergebnis\Version\BuildMetaData
Version
Create a Version
from a string
<?php declare(strict_types=1); use Ergebnis\Version; $version = Version\Version::fromString('1.2.3-alpha+build.9001'); echo $version->toString(); // 1.2.3 echo $version->major()->toString(); // 1 echo $version->minor()->toString(); // 2 echo $version->patch()->toString(); // 3 echo $version->preRelease()->toString(); // alpha echo $version->buildMetaData()->toString(); // build.9001
Bump a Version
<?php declare(strict_types=1); use Ergebnis\Version; $version = Version\Version::fromString('1.2.3'); $one = $version->bumpMajor(); echo $one->toString(); // 2.0.0 $two = $version->bumpMinor(); echo $two->toString(); // 1.3.0 $three = $version->bumpPatch(); echo $three->toString(); // 1.2.4
Bump a Version
with PreRelease
<?php declare(strict_types=1); use Ergebnis\Version; $version = Version\Version::fromString('1.2.3-alpha'); $one = $version->bumpMajor(); echo $one->toString(); // 2.0.0 $two = $version->bumpMinor(); echo $two->toString(); // 1.3.0 $three = $version->bumpPatch(); echo $three->toString(); // 1.2.3
Bump a Version
with BuildMetaData
<?php declare(strict_types=1); use Ergebnis\Version; $version = Version\Version::fromString('1.2.3+build.9001'); $one = $version->bumpMajor(); echo $one->toString(); // 2.0.0 $two = $version->bumpMinor(); echo $two->toString(); // 1.3.0 $three = $version->bumpPatch(); echo $three->toString(); // 1.2.4
Compare a Version
with another Version
<?php declare(strict_types=1); use Ergebnis\Version; $one = Version\Version::fromString('1.2.3-alpha'); $two = Version\Version::fromString('1.2.3'); $three = Version\Version::fromString('1.2.4'); $four = Version\Version::fromString('1.2.4+build.9001'); $one->compare($two); // -1 $one->compare($one); // 0 $three->compare($one); // 1 $one->isSmallerThan($one); // false $one->isSmallerThan($two); // true $one->isSmallerThan($three); // true $one->isSmallerThan($four); // true $one->equals($two); // false $one->equals($one); // true $one->equals($three); // false $three->equals($four); // true $one->isGreaterThan($one); // false $two->isGreaterThan($one); // true $three->isGreaterThan($one); // true $four->isGreaterThan($one); // true
Major
Create a Major
from an int
<?php declare(strict_types=1); use Ergebnis\Version; $major = Version\Major::fromInt(1); echo $major->toString(); // 1
Create a Major
from a string
<?php declare(strict_types=1); use Ergebnis\Version; $major = Version\Major::fromString('1'); echo $major->toString(); // 1
Bump a Major
<?php declare(strict_types=1); use Ergebnis\Version; $one = Version\Major::fromString('1'); $two = $one->bump(); echo $two->toString(); // 2
Compare a Major
with another Major
<?php declare(strict_types=1); use Ergebnis\Version; $one = Version\Major::fromString('1'); $two = Version\Major::fromString('2'); $one->compare($two); // -1 $one->compare($one); // 0 $two->compare($one); // 1 $one->isSmallerThan($one); // false $one->isSmallerThan($two); // true $one->equals($two); // false $one->equals($one); // true $one->isGreaterThan($one); // false $two->isGreaterThan($one); // true
Minor
Create a Minor
from an int
<?php declare(strict_types=1); use Ergebnis\Version; $minor = Version\Minor::fromInt(1); echo $minor->toString(); // 1
Create a Minor
from a string
<?php declare(strict_types=1); use Ergebnis\Version; $minor = Version\Minor::fromString('1'); echo $minor->toString(); // 1
Bump a Minor
<?php declare(strict_types=1); use Ergebnis\Version; $one = Version\Minor::fromString('1'); $two = $one->bump(); echo $two->toString(); // 2
Compare a Minor
with another Minor
<?php declare(strict_types=1); use Ergebnis\Version; $one = Version\Minor::fromString('1'); $two = Version\Minor::fromString('2'); $one->compare($two); // -1 $one->compare($one); // 0 $two->compare($one); // 1 $one->isSmallerThan($one); // false $one->isSmallerThan($two); // true $one->equals($two); // false $one->equals($one); // true $one->isGreaterThan($one); // false $two->isGreaterThan($one); // true
Patch
Create a Patch
from an int
<?php declare(strict_types=1); use Ergebnis\Version; $patch = Version\Patch::fromInt(1); echo $patch->toString(); // 1
Create a Patch
from a string
<?php declare(strict_types=1); use Ergebnis\Version; $patch = Version\Patch::fromString('1'); echo $patch->toString(); // 1
Bump a Patch
<?php declare(strict_types=1); use Ergebnis\Version; $one = Version\Patch::fromString('1'); $two = $one->bump(); echo $two->toString(); // 2
Compare a Patch
with another Patch
<?php declare(strict_types=1); use Ergebnis\Version; $one = Version\Patch::fromString('1'); $two = Version\Patch::fromString('2'); $one->compare($two); // -1 $one->compare($one); // 0 $two->compare($one); // 1 $one->isSmallerThan($one); // false $one->isSmallerThan($two); // true $one->equals($two); // false $one->equals($one); // true $one->isGreaterThan($one); // false $two->isGreaterThan($one); // true
PreRelease
Create a PreRelease
from a string
<?php declare(strict_types=1); use Ergebnis\Version; $preRelease = Version\PreRelease::fromString('alpha'); echo $preRelease->toString(); // alpha
Create an empty PreRelease
<?php declare(strict_types=1); use Ergebnis\Version; $preRelease = Version\PreRelease::empty(); echo $preRelease->toString(); // empty
Compare a PreRelease
with another PreRelease
<?php declare(strict_types=1); use Ergebnis\Version; $one = Version\PreRelease::fromString('alpha'); $two = Version\PreRelease::fromString('rc.1'); $one->compare($two); // -1 $one->compare($one); // 0 $two->compare($one); // 1 $one->isSmallerThan($one); // false $one->isSmallerThan($two); // true $one->equals($two); // false $one->equals($one); // true $one->isGreaterThan($one); // false $two->isGreaterThan($one); // true
BuildMetaData
Create a BuildMetaData
from a string
<?php declare(strict_types=1); use Ergebnis\Version; $buildMetaData = Version\BuildMetaData::fromString('build.9001'); echo $buildMetaData->toString(); // build.9001
Create an empty BuildMetaData
<?php declare(strict_types=1); use Ergebnis\Version; $buildMetaData = Version\BuildMetaData::empty(); echo $buildMetaData->toString(); // empty
Compare a BuildMetaData
with another BuildMetaData
<?php declare(strict_types=1); use Ergebnis\Version; $one = Version\BuildMetaData::fromString('build.9001'); $two = Version\BuildMetaData::fromString('build.9000'); $one->equals($two); // false $one->equals($one); // true
Changelog
The maintainers of this project record notable changes to this project in a changelog.
Contributing
The maintainers of this project suggest following the contribution guide.
Code of Conduct
The maintainers of this project ask contributors to follow the code of conduct.
General Support Policy
The maintainers of this project provide limited support.
You can support the maintenance of this project by sponsoring @localheinz or requesting an invoice for services related to this project.
PHP Version Support Policy
This project supports PHP versions with active and security support.
The maintainers of this project add support for a PHP version following its initial release and drop support for a PHP version when it has reached the end of security support.
Security Policy
This project has a security policy.
License
This project uses the MIT license.
Social
Follow @localheinz and @ergebnis on Twitter.