diff --git a/src/Router.php b/src/Router.php index 254cb41..958efdb 100644 --- a/src/Router.php +++ b/src/Router.php @@ -239,8 +239,8 @@ class Router ); $scanner->setConfig($scanConfig); - $normalizedAppPath = str_replace('\\', '/', APP_PATH . 'app'); - $normalizedRoutePath = str_replace('\\', '/', APP_PATH . 'routes'); + $normalizedAppPath = str_replace('\\', '/', realpath(APP_PATH . 'app') ?: APP_PATH . 'app'); + $normalizedRoutePath = str_replace('\\', '/', realpath(APP_PATH . 'routes') ?: APP_PATH . 'routes'); $routeChanged = false; $appChangedFiles = []; @@ -255,6 +255,10 @@ class Router } } + if (!empty($appChangedFiles)) { + $appChangedFiles = $scanner->expandDependentFiles($appChangedFiles, APP_PATH . 'app/'); + } + $usedArtifact = false; if (($scanConfig['cache_enabled'] ?? false) && !$routeChanged && $artifactState->has(static::$type)) { $artifact = $artifactState->load(static::$type); @@ -267,7 +271,7 @@ class Router $this->read_dir_file(APP_PATH . 'routes'); if (!$routeChanged && !empty($appChangedFiles) && ($scanConfig['cache_enabled'] ?? false)) { - $scanner->scanFiles($appChangedFiles, APP_PATH . 'app/', null, !$usedArtifact); + $scanner->scanFiles($appChangedFiles, APP_PATH . 'app/', null, true); } elseif (!$usedArtifact) { $scanner->scan(APP_PATH . 'app/'); } else { @@ -462,8 +466,12 @@ class Router private function resolve_file($files): void { try { - static::$currentSourceFile = str_replace('\\', '/', realpath($files) ?: $files); - include "$files"; + $file = realpath($files) ?: $files; + static::$currentSourceFile = str_replace('\\\\', '/', $file); + if (function_exists('opcache_invalidate')) { + @opcache_invalidate($file, true); + } + include $file; } catch (\Throwable $throwable) { \Kiri::getLogger()->json_log($throwable); } finally { @@ -471,7 +479,6 @@ class Router } } - public static function getCurrentSourceFile(): ?string { return static::$currentSourceFile;