mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-24 12:07:28 +08:00
feat: add multiple hooks, pligun schedule support ,add hook:list artisan command
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class HookList extends Command
|
||||
{
|
||||
protected $signature = 'hook:list';
|
||||
protected $description = '列出系统支持的所有 hooks(静态扫描代码)';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$paths = [base_path('app'), base_path('plugins')];
|
||||
$hooks = collect();
|
||||
$pattern = '/HookManager::(call|filter|register|registerFilter)\([\'\"]([a-zA-Z0-9_.-]+)[\'\"]/';
|
||||
|
||||
foreach ($paths as $path) {
|
||||
$files = collect(
|
||||
is_dir($path) ? (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path))) : []
|
||||
)->filter(fn($f) => Str::endsWith($f, '.php'));
|
||||
foreach ($files as $file) {
|
||||
$content = @file_get_contents($file);
|
||||
if ($content && preg_match_all($pattern, $content, $matches)) {
|
||||
foreach ($matches[2] as $hook) {
|
||||
$hooks->push($hook);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$hooks = $hooks->unique()->sort()->values();
|
||||
if ($hooks->isEmpty()) {
|
||||
$this->info('未扫描到任何 hook');
|
||||
} else {
|
||||
$this->info('All Supported Hooks:');
|
||||
foreach ($hooks as $hook) {
|
||||
$this->line(' ' . $hook);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use App\Services\Plugin\PluginManager;
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
@@ -25,7 +26,7 @@ class Kernel extends ConsoleKernel
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
protected function schedule(Schedule $schedule): void
|
||||
{
|
||||
Cache::put(CacheKey::get('SCHEDULE_LAST_CHECK_AT', null), time());
|
||||
// v2board
|
||||
@@ -48,7 +49,10 @@ class Kernel extends ConsoleKernel
|
||||
// 每分钟清理过期的在线状态
|
||||
$schedule->call(function () {
|
||||
app(UserOnlineService::class)->cleanExpiredOnlineStatus();
|
||||
})->everyMinute();
|
||||
})->everyMinute()->name('cleanup:expired-online-status')->onOneServer();
|
||||
|
||||
app(PluginManager::class)->registerPluginSchedules($schedule);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user