mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-15 12:30:51 +08:00
feat: add multiple hooks, pligun schedule support ,add hook:list artisan command
This commit is contained in:
@@ -2,35 +2,36 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Models\Plugin;
|
||||
use App\Services\Plugin\PluginManager;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Middleware to initialize all enabled plugins at the beginning of a request.
|
||||
* It ensures that all plugin hooks, routes, and services are ready.
|
||||
*/
|
||||
class InitializePlugins
|
||||
{
|
||||
protected $pluginManager;
|
||||
protected PluginManager $pluginManager;
|
||||
|
||||
public function __construct(PluginManager $pluginManager)
|
||||
{
|
||||
$this->pluginManager = $pluginManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
try {
|
||||
$plugins = Plugin::query()
|
||||
->where('is_enabled', true)
|
||||
->get();
|
||||
|
||||
foreach ($plugins as $plugin) {
|
||||
$this->pluginManager->enable($plugin->code);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Failed to load plugins: ' . $e->getMessage());
|
||||
}
|
||||
// This single method call handles loading and booting all enabled plugins.
|
||||
// It's safe to call multiple times, as it will only run once per request.
|
||||
$this->pluginManager->initializeEnabledPlugins();
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user