mergeConfigFrom( __DIR__ . '/config/cleanup.php', 'cleanup' ); // 注册服务单例 $this->app->singleton('cleanup.service', function ($app) { return new Services\CleanupService(); }); } /** * 启动服务 */ public function boot(): void { // 发布配置文件 $this->publishes([ __DIR__ . '/config/cleanup.php' => config_path('cleanup.php'), ], 'cleanup-config'); // 注册命令 if ($this->app->runningInConsole()) { $this->commands([ ScanTablesCommand::class, ScanModelsCommand::class, TestModelCleanupCommand::class, ValidateModelCleanupCommand::class, CleanupDataCommand::class, InsertCleanupAdminMenuCommand::class, ]); } // 注册事件监听器 $this->registerEventListeners(); // 路由通过 route-attributes 自动注册,无需手动注册 } /** * 注册事件监听器 */ protected function registerEventListeners(): void { // 任务状态变更事件 Event::listen( \App\Module\Cleanup\Events\TaskStatusChanged::class, \App\Module\Cleanup\Listeners\TaskStatusChangedListener::class ); // 备份完成事件 Event::listen( \App\Module\Cleanup\Events\BackupCompleted::class, \App\Module\Cleanup\Listeners\BackupCompletedListener::class ); // 清理完成事件 Event::listen( \App\Module\Cleanup\Events\CleanupCompleted::class, \App\Module\Cleanup\Listeners\CleanupCompletedListener::class ); } /** * 获取提供的服务 */ public function provides(): array { return [ 'cleanup.service', ]; } }