ergebnis/version
Composer 安装命令:
composer require ergebnis/version
包简介
Provides an abstraction of a semantic version.
README 文档
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\VersionErgebnis\Version\MajorErgebnis\Version\MinorErgebnis\Version\PatchErgebnis\Version\PreReleaseErgebnis\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 @ergebnis.
PHP Version Support Policy
This project currently supports the following PHP versions:
- PHP 7.4 (has reached its end of life on November 28, 2022)
- PHP 8.0 (has reached its end of life on November 26, 2023)
- PHP 8.1 (has reached its end of life on December 31, 2025)
- PHP 8.2
- PHP 8.3
- PHP 8.4
- PHP 8.5
The maintainers of this project add support for a PHP version following its initial release and may drop support for a PHP version when it has reached its end of life.
Security Policy
This project has a security policy.
License
This project uses the MIT license.
Social
Follow @localheinz and @ergebnis on Twitter.
ergebnis/version 适用场景与选型建议
ergebnis/version 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18.71k 次下载、GitHub Stars 达 18, 最近一次更新时间为 2023 年 12 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「version」 「semantic」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ergebnis/version 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ergebnis/version 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ergebnis/version 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
An extension to Semantic MediaWiki allowing to build breadcrumb links from an attributive property filter
Versioning behaviour for eloquent models
Minimal CSS Framework for semantic HTML.
Adds the EDTF data type to Wikibase
Converts SemVer version (like Composer packages) into integer version with operators. Helps managing versions: store, compare, sort and retrive by conditions.
Display a version number
统计信息
- 总下载量: 18.71k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 18
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-12-24