ergebnis / version
提供语义版本的抽象。
1.1.0
2024-03-10 12:44 UTC
Requires
- php: ~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0
Requires (Dev)
- ext-bcmath: *
- ergebnis/composer-normalize: ^2.42.0
- ergebnis/data-provider: ^3.2.0
- ergebnis/license: ^2.4.0
- ergebnis/php-cs-fixer-config: ^6.23.0
- ergebnis/phpunit-slow-test-detector: ^2.10.0
- fakerphp/faker: ^1.23.1
- infection/infection: ~0.26.6
- phpunit/phpunit: ^9.6.17
- psalm/plugin-phpunit: ~0.18.4
- rector/rector: ^1.0.2
- vimeo/psalm: ^5.23.0
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-09-09 22:00:52 UTC
README
此项目提供了一个 composer
包,该包提供语义版本的抽象。
安装
运行
composer require ergebnis/version
使用
此项目包含以下组件
Ergebnis\Version\Version
Ergebnis\Version\Major
Ergebnis\Version\Minor
Ergebnis\Version\Patch
Ergebnis\Version\PreRelease
Ergebnis\Version\BuildMetaData
版本
从字符串创建 Version
<?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
增加 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
使用 PreRelease
增加 Version
<?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
使用 BuildMetaData
增加 Version
<?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
比较两个 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
<?php declare(strict_types=1); use Ergebnis\Version; $major = Version\Major::fromInt(1); echo $major->toString(); // 1
从字符串创建 Major
<?php declare(strict_types=1); use Ergebnis\Version; $major = Version\Major::fromString('1'); echo $major->toString(); // 1
增加 Major
<?php declare(strict_types=1); use Ergebnis\Version; $one = Version\Major::fromString('1'); $two = $one->bump(); echo $two->toString(); // 2
比较两个 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
<?php declare(strict_types=1); use Ergebnis\Version; $minor = Version\Minor::fromInt(1); echo $minor->toString(); // 1
从字符串创建 Minor
<?php declare(strict_types=1); use Ergebnis\Version; $minor = Version\Minor::fromString('1'); echo $minor->toString(); // 1
增加 Minor
<?php declare(strict_types=1); use Ergebnis\Version; $one = Version\Minor::fromString('1'); $two = $one->bump(); echo $two->toString(); // 2
比较两个 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
<?php declare(strict_types=1); use Ergebnis\Version; $patch = Version\Patch::fromInt(1); echo $patch->toString(); // 1
从字符串创建 Patch
<?php declare(strict_types=1); use Ergebnis\Version; $patch = Version\Patch::fromString('1'); echo $patch->toString(); // 1
增加 Patch
<?php declare(strict_types=1); use Ergebnis\Version; $one = Version\Patch::fromString('1'); $two = $one->bump(); echo $two->toString(); // 2
比较两个 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
<?php declare(strict_types=1); use Ergebnis\Version; $preRelease = Version\PreRelease::fromString('alpha'); echo $preRelease->toString(); // alpha
创建空的 PreRelease
<?php declare(strict_types=1); use Ergebnis\Version; $preRelease = Version\PreRelease::empty(); echo $preRelease->toString(); // empty
比较两个 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
<?php declare(strict_types=1); use Ergebnis\Version; $buildMetaData = Version\BuildMetaData::fromString('build.9001'); echo $buildMetaData->toString(); // build.9001
创建空的 BuildMetaData
<?php declare(strict_types=1); use Ergebnis\Version; $buildMetaData = Version\BuildMetaData::empty(); echo $buildMetaData->toString(); // empty
比较两个 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
变更日志
此项目的维护者在 变更日志 中记录了此项目的重大变更。
贡献
此项目的维护者建议遵循 贡献指南。
行为准则
此项目的维护者要求贡献者遵守 行为准则。
一般支持策略
此项目的维护者提供有限的支持。
您可以通过 赞助 @localheinz 或 为此项目相关的服务请求发票 来支持此项目的维护。
PHP 版本支持策略
此项目支持具有 活动和安全支持 的 PHP 版本。
此项目的维护者在其初始发布后添加对 PHP 版本的支持,并在其达到安全支持结束时取消对该 PHP 版本的支持。
安全策略
此项目有一个 安全策略。
许可证
此项目使用 MIT 许可证。
社交
关注Twitter上的@localheinz和@ergebnis。