From 9a3ce255e7f376b2b078050a4e96c152648a3ae7 Mon Sep 17 00:00:00 2001 From: liyang Date: Thu, 26 Oct 2017 00:55:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=A4=9A=E7=BA=A7=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ApiDesc.php | 13 ++++++++----- src/ApiList.php | 16 +++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/ApiDesc.php b/src/ApiDesc.php index 2e9903f..24ce9e2 100644 --- a/src/ApiDesc.php +++ b/src/ApiDesc.php @@ -36,18 +36,21 @@ public function render() { $exploade_service = explode('/', $service); switch (count($exploade_service)) { - case 2: + case 2://不是模块 $classNameTpl = \Yii::$app->controllerNamespace . '\\%sController'; $className = sprintf($classNameTpl, ucfirst($exploade_service[0])); $methodName = 'action' .ucfirst($exploade_service[1]); break; - case 3: - $module = \Yii::$app->modules[$exploade_service['0']]['class']; + default://是模块 + //不论几级模块,倒数第三个一定是模块名 + $c = count($exploade_service); + $moduleName = $exploade_service[$c-3]; + $module = \Yii::$app->modules[$moduleName]['class']; $t = new \ReflectionClass($module); $moduleNamespace = $t->getNamespaceName(); $classNameTpl = $moduleNamespace . '\\controllers\\%sController'; - $className = sprintf($classNameTpl, ucfirst($exploade_service[1])); - $methodName = 'action' .ucfirst($exploade_service[2]); + $className = sprintf($classNameTpl, ucfirst($exploade_service[$c-2])); + $methodName = 'action' .ucfirst($exploade_service[$c-1]); break; } // 整合需要的类注释,包括父类注释 diff --git a/src/ApiList.php b/src/ApiList.php index 9753fb4..a717078 100644 --- a/src/ApiList.php +++ b/src/ApiList.php @@ -66,16 +66,14 @@ public function render($modules = []) { } foreach ($classesName as $className) { $explodeClassName = explode('\\', trim($className, '\\')); - switch (count($explodeClassName)) { - case 3: - $apiServerShortName = $explodeClassName[2]; - $service_1 = strtolower(substr($apiServerShortName, 0, -10)); - break; - case 5: - $apiServerShortName = $explodeClassName[2] . '.' . $explodeClassName[4]; - $service_1 = strtolower(substr($apiServerShortName, 0, -10)); - break; + $c = count($explodeClassName); + if ($c > 3) { + unset($explodeClassName[$c-2]); } + unset($explodeClassName[0]); + unset($explodeClassName[1]); + $apiServerShortName = implode('.', $explodeClassName);//ok + $service_1 = strtolower(substr($apiServerShortName, 0, -10)); $apiServer = $className; if (!class_exists($className)) { continue;