This commit is contained in:
2026-07-20 11:15:46 +08:00
parent 23e9d79e27
commit bf177c9158
+28 -6
View File
@@ -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] 等注解