PHP code example of ergebnis / version
1. Go to this page and download the library: Download ergebnis/version library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ergebnis / version example snippets
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
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
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
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
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
declare(strict_types=1);
use Ergebnis\Version;
$major = Version\Major::fromInt(1);
echo $major->toString(); // 1
declare(strict_types=1);
use Ergebnis\Version;
$major = Version\Major::fromString('1');
echo $major->toString(); // 1
declare(strict_types=1);
use Ergebnis\Version;
$one = Version\Major::fromString('1');
$two = $one->bump();
echo $two->toString(); // 2
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
declare(strict_types=1);
use Ergebnis\Version;
$minor = Version\Minor::fromInt(1);
echo $minor->toString(); // 1
declare(strict_types=1);
use Ergebnis\Version;
$minor = Version\Minor::fromString('1');
echo $minor->toString(); // 1
declare(strict_types=1);
use Ergebnis\Version;
$one = Version\Minor::fromString('1');
$two = $one->bump();
echo $two->toString(); // 2
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
declare(strict_types=1);
use Ergebnis\Version;
$patch = Version\Patch::fromInt(1);
echo $patch->toString(); // 1
declare(strict_types=1);
use Ergebnis\Version;
$patch = Version\Patch::fromString('1');
echo $patch->toString(); // 1
declare(strict_types=1);
use Ergebnis\Version;
$one = Version\Patch::fromString('1');
$two = $one->bump();
echo $two->toString(); // 2
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
declare(strict_types=1);
use Ergebnis\Version;
$preRelease = Version\PreRelease::fromString('alpha');
echo $preRelease->toString(); // alpha
declare(strict_types=1);
use Ergebnis\Version;
$preRelease = Version\PreRelease::empty();
echo $preRelease->toString(); // empty
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
declare(strict_types=1);
use Ergebnis\Version;
$buildMetaData = Version\BuildMetaData::fromString('build.9001');
echo $buildMetaData->toString(); // build.9001
declare(strict_types=1);
use Ergebnis\Version;
$buildMetaData = Version\BuildMetaData::empty();
echo $buildMetaData->toString(); // empty
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