mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-24 03:57:27 +08:00
feat: enhance plugin management
- Add command support for plugin management - Optimize plugin management page layout - Add email copy functionality for users - Convert payment methods and Telegram Bot to plugin system
This commit is contained in:
@@ -11,7 +11,6 @@ use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
class PluginManager
|
||||
{
|
||||
@@ -114,13 +113,25 @@ class PluginManager
|
||||
*/
|
||||
protected function loadViews(string $pluginCode): void
|
||||
{
|
||||
$viewsPath = $this->getPluginPath($pluginCode) . '/resources/views';
|
||||
|
||||
$viewsPath = $this->getPluginPath($pluginCode) . '/views';
|
||||
if (File::exists($viewsPath)) {
|
||||
View::addNamespace(Str::studly($pluginCode), $viewsPath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册插件命令
|
||||
*/
|
||||
protected function registerPluginCommands(string $pluginCode, AbstractPlugin $pluginInstance): void
|
||||
{
|
||||
try {
|
||||
// 调用插件的命令注册方法
|
||||
$pluginInstance->registerCommands();
|
||||
} catch (\Exception $e) {
|
||||
Log::error("Failed to register commands for plugin '{$pluginCode}': " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 安装插件
|
||||
*/
|
||||
@@ -163,6 +174,7 @@ class PluginManager
|
||||
'code' => $pluginCode,
|
||||
'name' => $config['name'],
|
||||
'version' => $config['version'],
|
||||
'type' => $config['type'] ?? Plugin::TYPE_FEATURE,
|
||||
'is_enabled' => false,
|
||||
'config' => json_encode($defaultValues),
|
||||
'installed_at' => now(),
|
||||
@@ -259,6 +271,14 @@ class PluginManager
|
||||
return false;
|
||||
}
|
||||
|
||||
// 验证插件类型
|
||||
if (isset($config['type'])) {
|
||||
$validTypes = ['feature', 'payment'];
|
||||
if (!in_array($config['type'], $validTypes)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -478,6 +498,7 @@ class PluginManager
|
||||
$this->registerServiceProvider($pluginCode);
|
||||
$this->loadRoutes($pluginCode);
|
||||
$this->loadViews($pluginCode);
|
||||
$this->registerPluginCommands($pluginCode, $pluginInstance);
|
||||
|
||||
$pluginInstance->boot();
|
||||
|
||||
@@ -535,4 +556,42 @@ class PluginManager
|
||||
|
||||
return array_intersect_key($this->loadedPlugins, array_flip($enabledPluginCodes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get enabled plugins by type
|
||||
*/
|
||||
public function getEnabledPluginsByType(string $type): array
|
||||
{
|
||||
$this->initializeEnabledPlugins();
|
||||
|
||||
$enabledPluginCodes = Plugin::where('is_enabled', true)
|
||||
->byType($type)
|
||||
->pluck('code')
|
||||
->all();
|
||||
|
||||
return array_intersect_key($this->loadedPlugins, array_flip($enabledPluginCodes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get enabled payment plugins
|
||||
*/
|
||||
public function getEnabledPaymentPlugins(): array
|
||||
{
|
||||
return $this->getEnabledPluginsByType('payment');
|
||||
}
|
||||
|
||||
/**
|
||||
* install default plugins
|
||||
*/
|
||||
public static function installDefaultPlugins(): void
|
||||
{
|
||||
foreach (Plugin::PROTECTED_PLUGINS as $pluginCode) {
|
||||
if (!Plugin::where('code', $pluginCode)->exists()) {
|
||||
$pluginManager = app(self::class);
|
||||
$pluginManager->install($pluginCode);
|
||||
$pluginManager->enable($pluginCode);
|
||||
Log::info("Installed and enabled default plugin: {$pluginCode}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user