41 lines
994 B
PHP
41 lines
994 B
PHP
<?php
|
|
|
|
namespace App\Blog\Providers;
|
|
|
|
use App\Blog\Support\PluginManager;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class PluginManagerServiceProvider extends ServiceProvider
|
|
{
|
|
public function register(): void
|
|
{
|
|
$this->app->singleton(PluginManager::class);
|
|
}
|
|
|
|
public function boot(): void
|
|
{
|
|
$manager = $this->app->make(PluginManager::class);
|
|
|
|
// 迁移尚未执行(migrate:fresh 首轮)时跳过,避免查询不存在的表
|
|
if (! \Illuminate\Support\Facades\Schema::hasTable('plugin_records')) {
|
|
return;
|
|
}
|
|
|
|
if (! is_dir(config('plugins.path'))) {
|
|
return;
|
|
}
|
|
|
|
foreach ($manager->all() as $key => $plugin) {
|
|
if (! $plugin['enabled']) {
|
|
continue;
|
|
}
|
|
|
|
$provider = $manager->resolveProvider($key);
|
|
|
|
if ($provider && class_exists($provider)) {
|
|
$provider::bootPlugin($manager);
|
|
}
|
|
}
|
|
}
|
|
}
|