From 91a289984078f6f434cddafb9642cfe636439e8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Wed, 14 Apr 2021 18:13:17 +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 --- Annotation/Loader.php | 14 ++++++++++++-- HttpServer/Events/OnWorkerStart.php | 4 ++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Annotation/Loader.php b/Annotation/Loader.php index e662c6cb..59a7c4c3 100644 --- a/Annotation/Loader.php +++ b/Annotation/Loader.php @@ -211,7 +211,7 @@ class Loader extends BaseObject public function loadByDirectory(string $path, ?string $outPath = null) { try { - $this->each($path); + $this->each($path, $outPath); } catch (Throwable $exception) { $this->addError($exception, 'throwable'); } @@ -258,14 +258,24 @@ class Loader extends BaseObject /** * @param string $filePath + * @param string|null $outPath * @return $this */ - private function each(string $filePath): static + private function each(string $filePath, ?string $outPath): static { $tree = null; $directory = $this->splitDirectory($filePath); + if (!empty($outPath)) { + $outPath = rtrim($outPath, '/'); + } + + $_tmp = ''; foreach ($directory as $key => $value) { + $_tmp .= DIRECTORY_SEPARATOR . $value; + if (str_contains($_tmp, $outPath)) { + break; + } $tree = $this->getTree($tree, $value); } if ($tree instanceof FileTree) { diff --git a/HttpServer/Events/OnWorkerStart.php b/HttpServer/Events/OnWorkerStart.php index 2d2b545a..39c4066c 100644 --- a/HttpServer/Events/OnWorkerStart.php +++ b/HttpServer/Events/OnWorkerStart.php @@ -85,10 +85,10 @@ class OnWorkerStart extends Callback { try { $time = microtime(true); - $annotation->runtime(directory('app')); + $annotation->runtime(CONTROLLER_PATH); $this->debug('load controller time .' . (microtime(true) - $time)); -// $annotation->runtime(directory('app'), CONTROLLER_PATH); + $annotation->runtime(directory('app'), CONTROLLER_PATH); name($server->worker_pid, 'Worker#' . $server->worker_id);