From bf177c91588d8951f73d2c79ee734644c720d26d Mon Sep 17 00:00:00 2001 From: whwyy Date: Mon, 20 Jul 2026 11:15:46 +0800 Subject: [PATCH] eee --- src/Router.php | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/Router.php b/src/Router.php index e544a06..94e0398 100644 --- a/src/Router.php +++ b/src/Router.php @@ -216,16 +216,18 @@ class Router $artifactState = $container->get(RouteArtifactState::class); if (getenv('KIRI_FILE_BUILD') !== '1' && !empty($changedFiles) && $artifactState->coversChangedFiles(static::$type, $changedFiles)) { - $container->get(DataGrip::class)->reset(static::$type); - $router = $container->get(DataGrip::class)->get(static::$type); - if ($router->importArtifact($artifactState->load(static::$type))) { - $this->read_dir_file(APP_PATH . 'routes'); - $this->reset($container); - $coordinator->done(); + if ($this->importRouteArtifact($container, $artifactState, $coordinator)) { return; } } + if (getenv('KIRI_FILE_BUILD') !== '1' && empty($changedFiles) && (bool)config('servers.reload.hot', false) && $artifactState->has(static::$type)) { + if ($this->importRouteArtifact($container, $artifactState, $coordinator)) { + return; + } + } + + // Worker 首次启动(无变更文件 + Master 已完成扫描): // 重新 include 路由文件(Router::get/post 显式注册) + 基于 Master 扫描清单重建注解路由 // 避免 opcache_compile_file,仅用 Reflection 重建路由,内存开销极小 @@ -312,6 +314,26 @@ class Router } + private function importRouteArtifact(ContainerInterface $container, RouteArtifactState $artifactState, Coordinator $coordinator): bool + { + $artifact = $artifactState->load(static::$type); + $container->get(DataGrip::class)->reset(static::$type); + $router = $container->get(DataGrip::class)->get(static::$type); + if (!$router->importArtifact($artifact)) { + return false; + } + + if (($artifact['has_closure_routes'] ?? false) === true) { + $this->read_dir_file(APP_PATH . 'routes'); + } + + $this->reset($container); + $coordinator->done(); + return true; + } + + + /** * 基于 Master 扫描清单重建注解路由(轻量级,无文件 I/O) * 遍历 Scanner manifest 中的所有类,用 Reflection 重新发现 #[Route]/#[Get] 等注解