hnhdigital-os / laravel-console-self-update
提供了一个特性,用于更新控制台二进制文件。
Requires
- php: ^7.1.3
Requires (Dev)
- mockery/mockery: ^1.0
- phpmd/phpmd: ~2.0
- phpunit/phpunit: ^7.3
- squizlabs/php_codesniffer: ~3.0
This package is auto-updated.
Last update: 2024-09-08 15:49:25 UTC
README
.__ _____ .___ __
______ ____ | |_/ ____\ __ ________ __| _/____ _/ |_ ____
/ ___// __ \| |\ __\ ______ | | \____ \ / __ |\__ \\ __\/ __ \
\___ \\ ___/| |_| | /_____/ | | / |_> > /_/ | / __ \| | \ ___/
/____ >\___ >____/__| |____/| __/\____ |(____ /__| \___ >
\/ \/ |__| \/ \/ \/
提供特性,用于为 Laravel Zero 控制台应用程序提供自更新功能。
本包由澳大利亚精品开发商 H&H|Digital 开发。访问我们的网站:hnh.digital。
要求
- PHP 7.1.3
- Laravel Zero 5.7
安装
composer require hnhdigital-os/laravel-console-self-update
实现
此包通过特性和一个接口(用于常量)实现。
基本实现需要在调用 runSelfUpdate
方法之前设置基本 URL setUrl
或提供 flysystem 适配器 setFlysystem
。
二进制版本控制使用 BRANCH-TAG(例如 stable-1.00),但将回退到 TAG(1.0.0)以兼容更常见的 Laravel Zero 版本方法。
<?php namespace App\Commands; use HnhDigital\LaravelConsoleSelfUpdate\SelfUpdateInterface; use HnhDigital\LaravelConsoleSelfUpdate\SelfUpdateTrait; use LaravelZero\Framework\Commands\Command; class SelfUpdateCommand extends Command implements SelfUpdateInterface { use SelfUpdateTrait; /** * The signature of the command. * * @var string */ protected $signature = 'self-update {--tag=0 : Set a specific tag to install} {--check-version : Return the version of this current binary}'; /** * The description of the command. * * @var string */ protected $description = 'Self-update this binary'; /** * Execute the console command. * * @return mixed */ public function handle() { $this->setUrl('https://example.com'); $this->runSelfUpdate(); } }
最新版本
脚本检查 /latest
以获取最新标签(例如,它将包含 1.0.1)。
二进制下载路径
特定二进制版本的下载路径来自 /versions
中的 JSON 编码值(默认)。您可以使用 setVersionsPath
覆盖它。
{ "1.0.0": "download/1.0.0/example-file", "1.0.1": "download/1.0.1/example-file" }
默认情况下,版本文件是 tag/path。如果版本文件包含路径以外的内容,则默认路径源可以使用 setVersionsTagKey
覆盖到特定键。
例如
{ "1.0.0": {"path": "download/1.0.0/example-file"}, "1.0.1": {"path": "download/1.0.1/example-file"} }
... public function handle() { ... $this->setVersionsTagKey('path'); ... } ...
哈希比较
下载的文件将进行哈希检查(SHA256)。默认情况下,此哈希字符串位于下载文件路径相同的路径中(download/1.0.1/sha256)。
您可以通过重写 setHashSource
方法并返回不同的常量来更改默认源。
如果存在存储哈希的顶层 JSON 编码文件,将源设置为 CHECKSUM_TOP_LEVEL
。使用 setHashPath
指定文件路径。
注意:此数组以通过版本文件发现的下载路径为键。它必须匹配才能检索哈希。
... public function handle() { ... $this->setHashSource(self::CHECKSUM_TOP_LEVEL); $this->setHashPath('checksums'); ... } ...
{ "download/1.0.0/example-file": "...", "download/1.0.1/example-file": "..." }
如果哈希包含在版本文件中,则将源设置为 CHECKSUM_VERSIONS
。使用 setHashPath
指定数组键。
... public function handle() { ... $this->setHashSource(self::CHECKSUM_VERSIONS); $this->setHashPath('sha256'); ... } ...
{ "1.0.0": {"path": "download/1.0.0/example-file", "sha256": "..."}, "1.0.1": {"path": "download/1.0.1/example-file", "sha256": "..."} }
构建脚本
寻找构建脚本以帮助创建所有必要的文件?
贡献
有关详细信息,请参阅 CONTRIBUTING。
致谢
许可
MIT 许可证(MIT)。有关更多信息,请参阅 许可文件。