背景
- 因大量的kernel立commands註冊和調度配置信息,不同時段的多人員開發,造成git衝突
- 註冊和調度信息過多,造成維護困難
安裝
composer require qklin/laravel-kernel-plus
config/app.php
'providers' => [
...
Qklin\Kernel\Plus\KernelPlusProvider::class,
]
説明
# 會加載註冊所有的comand命令腳本,並自動加入schedule隊列, 無需手動個添加
php artisan schedule:run
# 自動註冊command,並執行
php artisan c:cmd:core:test
註解説明
command::handle()
// * @command true //註冊command
// * @commandParams param1=foo&--option=1 //本參數可省略
// * @schedule true //加入schedule
// * @runTime everyMinute //無參數的所有方法都支持
// * @runTime cron|* * * * * // 目前只支持cron帶參數,方法和參數[|]分隔
// * @withoutOverlapping true
// * @runInBackground true
// * @appendOutputTo test/log //記錄日誌,位置:storage目錄
// * @deprecated
env
默認的env配置
KERNEL_PLUS_ORIGIN_PREFIX=c
KERNEL_PLUS_MODULE_PREFIX=cm
KERNEL_PLUS_MODULE_DIR=Biz
KERNEL_PLUS_COMMANDS_DIR=cmd
KERNEL_DOCMENT_CMD=command
KERNEL_DOCMENT_CMD_PARAM=commandParams
KERNEL_DOCMENT_SCHEDULE=schedule
KERNEL_DOCMENT_RUN_TIME=runTime
KERNEL_DOCMENT_RUN)BACKGROUND=runInBackground
KERNEL_DOCMENT_LOG=appendOutputTo
KERNEL_DOCMENT_OVER_LAPPING=withoutOverlapping
KERNEL_DOCMENT_DEPRACATED=deprecated
demo
<?php
namespace App\Console\Commands\Core;
use App\Console\BaseCommand;
class Test extends BaseCommand
{
// 依賴關係
// 自動解決依賴,適用於單腳本依賴,不適用http
const DEPENDS = [
Testdepend::class
];
// 腳本命令註冊名
const COMMAND_SIGN = 'c:cmd:core:test';
protected $signature = self::COMMAND_SIGN . ' {param1?}';
protected $description = '自動注入腳本測試';
/**
* @command true
* @schedule true
* @runTime everyMinute
* @runTime cron|* 1 * * *
* @withoutOverlapping true
* @runInBackground true
* @appendOutputTo logs/c_core_test
*/
public function handle()
{
$this->info("test finish");
}
}