m3m0r7/git-version

基于 Git 提交哈希的 PHP 版本管理器(不使用 git 命令)

该软件包的规范仓库似乎已丢失,因此该软件包已被冻结。

0.1.1 2021-03-20 06:49 UTC

This package is auto-updated.

Last update: 2023-06-20 12:04:25 UTC


README

|日语|英语|

Git Version - 基于 Git 提交哈希的 PHP 版本管理器

许多库在原则上需要执行 git 命令,这会不必要地启动一个单独的过程。此外,有许多开发者自定义 git 命令或注册别名来改变其行为,并且在库中存在一个问题,即无法替换 git 命令。这个库根本不使用 git 命令,但允许您通过检索提交哈希和版本化标签值来安全地版本化您的 PHP 代码。

要求

  • PHP >= 7.2

安装

composer require m3m0r7/git-version

获取最后一个提交哈希

如果您想获取最后一个提交哈希,请编写如下代码。

<?php

declare(strict_types=1);

use GitVersion\Version;

require __DIR__ . '/vendor/autoload.php';

$version = Version::make(
    // Specified to `.git` directory path
    __DIR__
);

echo $version->getHash() . "\n";

结果如下

8bd8cfcff3b2b0fb22ab5e42be7f38f5a74e3d5f

如果要将第一个参数设置为 true,则获取短提交哈希。

<?php
declare(strict_types=1);

use GitVersion\Version;

require __DIR__ . '/vendor/autoload.php';

$version = Version::make(
    // Specified to `.git` directory path
    __DIR__
);

echo $version->getHash(true) . "\n";

结果如下

8bd8cfcf

获取版本化标签

如果您想获取版本化标签,请编写如下代码。

<?php

declare(strict_types=1);

use GitVersion\Version;

require __DIR__ . '/vendor/autoload.php';

$version = Version::make(
    // Specified to `.git` directory path
    __DIR__
);

$versionedTag = $version->getVersionedTag();

echo $versionedTag->getVersion() . "\n";
echo $versionedTag->getHash() . "\n";

结果如下

0.0.2
2c80da2c2aa5767a5a8f89b4c78135a4dbc3e8e9

如果要将版本指定为 Version::getVersionedTag 的第一个参数,则获取指定版本化标签。

<?php

declare(strict_types=1);

use GitVersion\Version;

require __DIR__ . '/vendor/autoload.php';

$version = Version::make(
    // Specified to `.git` directory path
    __DIR__
);

$versionedTag = $version->getVersionedTag('0.0.1');

echo $versionedTag->getVersion() . "\n";
echo $versionedTag->getHash() . "\n";

结果如下

0.0.1
b425291e8eaf03c0c0b6948015826bb2e5049019

如果要将第一个参数设置为 true,则获取短提交哈希,如上所述。

<?php

declare(strict_types=1);

use GitVersion\Version;

require __DIR__ . '/vendor/autoload.php';

$version = Version::make(
    // Specified to `.git` directory path
    __DIR__
);

$versionedTag = $version->getVersionedTag();

echo $versionedTag->getVersion() . "\n";
echo $versionedTag->getHash(true) . "\n";

结果如下

0.0.2
2c80da2c

PHPUnit 测试

./vendor/bin/phpunit ./tests