diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index 5d2a509a..ba2ad011 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -5,7 +5,6 @@ namespace Kiri\FileListen; use Exception; use Kiri; use Kiri\Abstracts\Config; -use Kiri\Annotation\Inject; use Kiri\Core\Json; use Kiri\Error\StdoutLoggerInterface; use Kiri\Exception\ConfigException; @@ -39,7 +38,6 @@ class HotReload extends Command public Inotify|Scaner $driver; - #[Inject(StdoutLoggerInterface::class)] public StdoutLoggerInterface $logger; @@ -55,6 +53,8 @@ class HotReload extends Command protected function configure() { $this->setName('sw:wather')->setDescription('server start'); + + $this->logger = Kiri::getDi()->get(StdoutLoggerInterface::class); } @@ -67,9 +67,9 @@ class HotReload extends Command set_error_handler([$this, 'errorHandler']); $this->dirs = Config::get('inotify', [APP_PATH . 'app']); if (!extension_loaded('inotify')) { - $this->driver = Kiri::getDi()->make(Scaner::class, [$this->dirs, $this]); + $this->driver = make(Scaner::class, [$this->dirs, $this, $this->logger]); } else { - $this->driver = Kiri::getDi()->make(Inotify::class, [$this->dirs, $this]); + $this->driver = make(Inotify::class, [$this->dirs, $this, $this->logger]); } $this->clearOtherService(); $this->setProcessName(); diff --git a/kiri-engine/FileListen/Inotify.php b/kiri-engine/FileListen/Inotify.php index 7ba48c72..a61bc10d 100644 --- a/kiri-engine/FileListen/Inotify.php +++ b/kiri-engine/FileListen/Inotify.php @@ -27,8 +27,10 @@ class Inotify /** * @param array $dirs * @param HotReload $process + * @param StdoutLoggerInterface $logger + * */ - public function __construct(protected array $dirs, public HotReload $process) + public function __construct(protected array $dirs, public HotReload $process, public StdoutLoggerInterface $logger) { set_error_handler([$this, 'error']); set_exception_handler([$this, 'error']); @@ -103,7 +105,7 @@ class Inotify */ public function reload($path) { - \Kiri::getDi()->get(StdoutLoggerInterface::class)->warning('file change'); + $this->logger->warning('file change'); $this->process->trigger_reload($path); $this->process->int = -1; @@ -137,8 +139,7 @@ class Inotify { //目录不存在 if (!is_dir($dir)) { - logger()->addError("[$dir] is not a directory."); - return false; + return $this->logger->addError("[$dir] is not a directory."); } //避免重复监听 if (isset($this->watchFiles[$dir])) { diff --git a/kiri-engine/FileListen/Scaner.php b/kiri-engine/FileListen/Scaner.php index 0fab051a..8f2920d5 100644 --- a/kiri-engine/FileListen/Scaner.php +++ b/kiri-engine/FileListen/Scaner.php @@ -17,7 +17,7 @@ class Scaner * @param array $dirs * @param HotReload $process */ - public function __construct(protected array $dirs, public HotReload $process) + public function __construct(protected array $dirs, public HotReload $process, public StdoutLoggerInterface $logger) { } @@ -113,7 +113,7 @@ class Scaner { $this->isReloading = TRUE; - \Kiri::getDi()->get(StdoutLoggerInterface::class)->warning('file change'); + $this->logger->warning('file change'); $this->process->trigger_reload($path);