语义版本控制辅助库
v0.3.3
2024-04-29 19:28 UTC
Requires
- php: ^7.1|^8.0
Requires (Dev)
- phpstan/phpstan: ^0.12.33
- phpstan/phpstan-phpunit: ^0.12.13
- phpunit/phpunit: ^7.3.2|^8.5.12|^9.6
- symfony/phpunit-bridge: ^5.2 || ^6.4
README
这是一个小的语义版本控制辅助库。
验证继续版本。寻找下一个可能的版本增量。
要求
您至少需要 PHP 7.1
安装
要安装此包,请在您的 composer.json 中添加 rollerworks/version
$ php composer.phar require rollerworks/version
此命令要求您全局安装 Composer,如 Composer 文档中的 安装章节 所述。
现在,Composer 将自动下载所有必需的文件,并为您安装它们。
基本用法
require 'vendor/autoload.php'; use Rollerworks\Component\Version\Version; use Rollerworks\Component\Version\VersionsValidator; // Creates an immutable Version value-object. // Any call to this object will produce a new Version object $version = Version::fromString('v1.3.2'); $newVersion = $version->increase('major'); // v2.0.0 $newVersion = $version->increase('minor'); // v1.4.0 $newVersion = $version->increase('next'); // v1.4.0 $newVersion = $version->increase('patch'); // v1.3.3 $newVersion = $version->increase('stable'); // v1.4.0 $newVersion = $version->increase('alpha'); // v1.4.0-ALPHA1 $newVersion = $version->increase('beta'); // v1.4.0-BETA1 $newVersion = $version->increase('rc'); // v1.4.0-RC1 // ... // Increasing minor or patch is prohibited until the meta-ver (alpha,beta,rc) is 0 // For patch this resolves to "next". $version = Version::fromString('v1.4.0-BETA1'); $newVersion = $version->increase('beta'); // v1.4.0-BETA2 $newVersion = $version->increase('rc'); // v1.4.0-RC1 $newVersion = $version->increase('major'); // v1.4.0 $newVersion = $version->increase('next'); // v1.4.0-BETA2 $newVersion = $version->increase('patch'); // v1.4.0-BETA2 $newVersion = $version->increase('stable'); // v1.4.0 // Version validation // ... // $existingVersions = [ Version::fromString('0.1.0'), Version::fromString('v1.0.0-beta1'), Version::fromString('v1.0.0-beta2'), Version::fromString('v1.0.0-beta6'), Version::fromString('v1.0.0-beta7'), Version::fromString('1.0.0'), Version::fromString('v1.0.1'), Version::fromString('v1.1.0'), Version::fromString('v2.0.0'), Version::fromString('v3.5-beta1'), ]; $validator = new ContinuesVersionsValidator(...$existingVersions); // Expects the versions as a variadic arguments //$validator = new ContinuesVersionsValidator(); // No existing versions VersionsValidator::isVersionContinues(Version::fromString('v1.1.1')); // true VersionsValidator::isVersionContinues(Version::fromString('1.0.2')); // true VersionsValidator::isVersionContinues(Version::fromString('1.1.1.')); // true VersionsValidator::isVersionContinues(Version::fromString('2.0.1.')); // true VersionsValidator::isVersionContinues(Version::fromString('3.5.0-beta2')); // true VersionsValidator::isVersionContinues(Version::fromString('3.5.0')); // true // A new minor or major version is not considered acceptable when there are already higher // versions. Only patch releases are accepted then. VersionsValidator::isVersionContinues(Version::fromString('0.2.0')); // false VersionsValidator::isVersionContinues(Version::fromString('v1.0.0-beta8')); // false VersionsValidator::isVersionContinues(Version::fromString('v1.2')); // false VersionsValidator::isVersionContinues(Version::fromString('v2.1')); // false VersionsValidator::isVersionContinues(Version::fromString('v3.5-alpha1')); // false VersionsValidator::isVersionContinues(Version::fromString('v3.5-beta3')); // false VersionsValidator::isVersionContinues(Version::fromString('v3.6')); // false // A list of possible versions with respect to the major.minor bounds of any existing version // For higher major.minor versions then validated only suggests a patch release, otherwise // all possible increments till the next stable major are suggested. $possibleVersions = $validator->getPossibleVersions();
版本控制
为了透明度和对发布周期的洞察,并努力保持向后兼容性,尽可能在这个包中按照语义版本控制指南进行维护。
发布将以以下格式编号
<主版本>.<次版本>.<修订版本>
并遵循以下指南
- 破坏向后兼容性时增加主版本(并重置次版本和修订版本)
- 没有破坏向后兼容性的新功能增加次版本(并重置修订版本)
- 错误修复和杂项更改增加修订版本
有关 SemVer 的更多信息,请访问 http://semver.org/。
许可证
此包的源代码受 MIT 许可证的约束,该许可证包含在此源代码的文件 LICENSE 中。
此库由 Sebastiaan Stok 维护。