From 4705613884e1bb493d046c78c907a5826e88c984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Thu, 18 Mar 2021 18:41:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- System/Process/ServerInotify.php | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/System/Process/ServerInotify.php b/System/Process/ServerInotify.php index 7515c107..093ea41e 100644 --- a/System/Process/ServerInotify.php +++ b/System/Process/ServerInotify.php @@ -13,6 +13,7 @@ namespace Snowflake\Process; use Exception; use Snowflake\Abstracts\Config; use Snowflake\Exception\ComponentException; +use Snowflake\Exception\ConfigException; use Snowflake\Snowflake; use Swoole\Coroutine; use Swoole\Event; @@ -58,15 +59,24 @@ class ServerInotify extends Process Event::add($this->inotify, [$this, 'check']); Event::wait(); } else { - $this->loadByDir(APP_PATH . 'app'); - $this->loadByDir(APP_PATH . 'routes'); - $this->loadByDir(__DIR__ . '/../../'); - + $this->loadDirs(); $this->tick(); } } + /** + * @param bool $isReload + * @throws Exception + */ + private function loadDirs($isReload = false) + { + foreach ($this->dirs as $value) { + $this->loadByDir(realpath($value), $isReload); + } + } + + private array $md5Map = []; @@ -78,9 +88,8 @@ class ServerInotify extends Process if ($this->isReloading) { return; } - $this->loadByDir(APP_PATH . 'app', true); - $this->loadByDir(APP_PATH . 'routes', true); - $this->loadByDir(__DIR__ . '/../../', true); + + $this->loadDirs(true); Timer::after(2000, [$this, 'tick']); } @@ -201,9 +210,7 @@ class ServerInotify extends Process $this->trigger_reload(); $this->int = -1; - $this->loadByDir(APP_PATH . 'app'); - $this->loadByDir(APP_PATH . 'routes'); - $this->loadByDir(__DIR__ . '/../../'); + $this->loadDirs(); $this->isReloading = FALSE; $this->isReloadingOut = FALSE; @@ -241,7 +248,7 @@ class ServerInotify extends Process * @param $message * @param $file * @param $line - * @throws ComponentException + * @throws Exception */ protected function onErrorHandler($code, $message, $file, $line) {