From ee04005d691a922f3045d4cae9729d3a19661eb4 Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Wed, 24 Jun 2020 09:11:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9E=B6=E6=9E=84=E8=B0=83=E6=95=B4=EF=BC=8C?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/catcher/CatchAdminService.php | 49 ++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/extend/catcher/CatchAdminService.php b/extend/catcher/CatchAdminService.php index ac0cc94..eed2987 100644 --- a/extend/catcher/CatchAdminService.php +++ b/extend/catcher/CatchAdminService.php @@ -18,6 +18,7 @@ use catcher\command\Tools\ExportDataCommand; use catcher\command\Tools\MakeMenuCommand; use catcher\command\worker\ExcelTaskCommand; use catcher\command\worker\WsWorkerCommand; +use catcher\event\LoadModuleRoutes; use think\exception\Handle; use think\facade\Validate; use think\Service; @@ -30,8 +31,7 @@ class CatchAdminService extends Service * @return void */ public function boot() - { - } + {} /** * register @@ -49,6 +49,8 @@ class CatchAdminService extends Service $this->registerEvents(); $this->registerQuery(); $this->registerExceptionHandle(); + $this->registerRoutePath(); + $this->registerServices(); } /** @@ -113,7 +115,9 @@ class CatchAdminService extends Service */ protected function registerEvents(): void { - $this->app->event->listenEvents(config('catch.events')); + $this->app->event->listenEvents([ + 'RouteLoaded' => [LoadModuleRoutes::class] + ]); } /** @@ -143,4 +147,43 @@ class CatchAdminService extends Service { $this->app->bind(Handle::class, CatchExceptionHandle::class); } + + /** + * 注册模块服务 + * + * @time 2020年06月23日 + * @return void + */ + protected function registerServices() + { + $services = CatchAdmin::getEnabledService(); + + foreach ($services as $service) { + if (class_exists($service)) { + $this->app->register($service); + } + } + } + + /** + * 注册路由地址 + * + * @time 2020年06月23日 + * @return void + */ + protected function registerRoutePath() + { + $this->app->instance('routePath', new class { + protected $path = []; + public function loadRouterFrom($path) + { + $this->path[] = $path; + return $this; + } + public function get() + { + return $this->path; + } + }); + } }