Skip to content
This repository has been archived by the owner on Apr 26, 2020. It is now read-only.

Commit

Permalink
支持多级模块
Browse files Browse the repository at this point in the history
  • Loading branch information
coder-liyang committed Oct 25, 2017
1 parent 96011b1 commit 9a3ce25
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
13 changes: 8 additions & 5 deletions src/ApiDesc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
// 整合需要的类注释,包括父类注释
Expand Down
16 changes: 7 additions & 9 deletions src/ApiList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9a3ce25

Please sign in to comment.