From c10d6c6cc78ae1ffd000f14fb8aa4fb4f43bd39d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=BC=E5=90=B8=E4=BA=8C=E6=B0=A7=E5=8C=96=E7=A2=B3?= Date: Thu, 4 May 2017 15:17:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84API=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Action.php | 1 + src/WorkerAPI.php | 40 +++++++++++++++++++--------------------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/Action.php b/src/Action.php index 4a563d2..86606fb 100644 --- a/src/Action.php +++ b/src/Action.php @@ -129,6 +129,7 @@ public static function loadAction($dir, $group = 'default') $list = []; foreach ((array)$dir as $item) { + if (!is_dir($item))continue; $item = rtrim($item, '/') . '/'; self::loadActionFileList($list, $item, strlen($item)); } diff --git a/src/WorkerAPI.php b/src/WorkerAPI.php index bf4b4aa..57e7b0e 100644 --- a/src/WorkerAPI.php +++ b/src/WorkerAPI.php @@ -17,13 +17,6 @@ class WorkerAPI extends Worker */ public $prefixLength = 5; - /** - * API 文件所在目录, 默认为根目录下 api 目录 - * - * @var string - */ - public $dir; - public $actionGroup = 'api'; public function __construct($server, $name) @@ -36,20 +29,8 @@ public function __construct($server, $name) } $this->prefixLength = strlen($this->prefix); - if (isset($this->setting['dir']) && $this->setting['dir']) - { - $this->dir = $this->setting['dir']; - } - else - { - $this->dir = realpath(__DIR__ .'/../../../../') . '/api/'; - } - # 读取列表 - if (is_dir($this->dir)) - { - Action::loadAction($this->dir, $this->actionGroup); - } + Action::loadAction($this->getActionPath(), $this->actionGroup); } /** @@ -145,7 +126,7 @@ public function onRequest($request, $response) */ public function reloadAction($reloadAll = false) { - return Action::reloadAction($this->dir, $this->actionGroup, $reloadAll); + return Action::reloadAction($this->getActionPath(), $this->actionGroup, $reloadAll); } /** @@ -191,6 +172,23 @@ protected function uri($request) return strtolower(trim($uri, '/')); } + /** + * 获取目录 + * + * @return array + */ + protected function getActionPath() + { + if (isset($this->setting['dir']) && $this->setting['dir']) + { + return (array)$this->setting['dir']; + } + else + { + return [realpath(__DIR__ . '/../../../../') . '/api/']; + } + } + /** * 验证API是否通过 *