ergebnis/version

提供语义版本的抽象。

1.1.0 2024-03-10 12:44 UTC

This package is auto-updated.

Last update: 2024-09-09 22:00:52 UTC


README

Integrate Merge Release Renew

Code Coverage Type Coverage

Latest Stable Version Total Downloads Monthly Downloads

此项目提供了一个 composer 包,该包提供语义版本的抽象。

安装

运行

composer require ergebnis/version

使用

此项目包含以下组件

版本

从字符串创建 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