This project provides a composer
package with an abstraction of a semantic version.
Run
composer require ergebnis/version
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
<?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
<?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
<?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
<?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
<?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
<?php
declare(strict_types=1);
use Ergebnis\Version;
$major = Version\Major::fromInt(1);
echo $major->toString(); // 1
<?php
declare(strict_types=1);
use Ergebnis\Version;
$major = Version\Major::fromString('1');
echo $major->toString(); // 1
<?php
declare(strict_types=1);
use Ergebnis\Version;
$one = Version\Major::fromString('1');
$two = $one->bump();
echo $two->toString(); // 2
<?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
<?php
declare(strict_types=1);
use Ergebnis\Version;
$minor = Version\Minor::fromInt(1);
echo $minor->toString(); // 1
<?php
declare(strict_types=1);
use Ergebnis\Version;
$minor = Version\Minor::fromString('1');
echo $minor->toString(); // 1
<?php
declare(strict_types=1);
use Ergebnis\Version;
$one = Version\Minor::fromString('1');
$two = $one->bump();
echo $two->toString(); // 2
<?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
<?php
declare(strict_types=1);
use Ergebnis\Version;
$patch = Version\Patch::fromInt(1);
echo $patch->toString(); // 1
<?php
declare(strict_types=1);
use Ergebnis\Version;
$patch = Version\Patch::fromString('1');
echo $patch->toString(); // 1
<?php
declare(strict_types=1);
use Ergebnis\Version;
$one = Version\Patch::fromString('1');
$two = $one->bump();
echo $two->toString(); // 2
<?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
<?php
declare(strict_types=1);
use Ergebnis\Version;
$preRelease = Version\PreRelease::fromString('alpha');
echo $preRelease->toString(); // alpha
<?php
declare(strict_types=1);
use Ergebnis\Version;
$preRelease = Version\PreRelease::empty();
echo $preRelease->toString(); // empty
<?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
<?php
declare(strict_types=1);
use Ergebnis\Version;
$buildMetaData = Version\BuildMetaData::fromString('build.9001');
echo $buildMetaData->toString(); // build.9001
<?php
declare(strict_types=1);
use Ergebnis\Version;
$buildMetaData = Version\BuildMetaData::empty();
echo $buildMetaData->toString(); // empty
<?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
The maintainers of this project record notable changes to this project in a changelog.
The maintainers of this project suggest following the contribution guide.
The maintainers of this project ask contributors to follow the code of conduct.
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.
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.
This project has a security policy.
This project uses the MIT license.
Follow @localheinz and @ergebnis on Twitter.