[ SystemEventListener::class . '@handleConfigChanged', ], ViewConfigChangedEvent::class => [ SystemEventListener::class . '@handleViewConfigChanged', ], SystemLogCreatedEvent::class => [ SystemEventListener::class . '@handleSystemLogCreated', ], ]; /** * 需要注册的订阅者 * * @var array */ protected $subscribe = [ SystemEventListener::class, ]; /** * 注册服务 * * @return void */ public function register(): void { // 不注册服务 // // 注册服务... // $this->app->singleton('system.config.service', function ($app) { // return new \App\Module\System\Services\ConfigService(); // }); // // $this->app->singleton('system.view.config.service', function ($app) { // return new \App\Module\System\Services\ViewConfigService(); // }); // // $this->app->singleton('system.log.service', function ($app) { // return new \App\Module\System\Services\LogService(); // }); } /** * 启动服务 * * @return void */ public function boot(): void { // 注册事件监听器 $this->registerEvents(); // 注册命令 $this->registerCommands(); // 注册定时任务 $this->registerSchedules(); } /** * 注册事件和监听器 * * @return void */ protected function registerEvents(): void { $events = $this->app['events']; foreach ($this->listen as $event => $listeners) { foreach ($listeners as $listener) { $events->listen($event, $listener); } } foreach ($this->subscribe as $subscriber) { $events->subscribe($subscriber); } } /** * 注册命令 * * @return void */ protected function registerCommands(): void { if ($this->app->runningInConsole()) { $this->commands([ CleanJobRunsCommand::class, InsertSystemLogAdminMenu::class, ]); } } /** * 注册System模块相关的定时任务 * * @return void */ protected function registerSchedules(): void { // 在应用完全启动后注册定时任务 $this->app->booted(function () { $schedule = $this->app->make(Schedule::class); // 每小时清理job_runs表,保留5天数据 $schedule->command('system:clean-job-runs') ->hourly() ->description('清理job_runs表过期记录(保留5天)') ->withoutOverlapping() // 防止重复执行 ->runInBackground(); // 后台运行 }); } }