diff --git a/README.md b/README.md index 3b4b7a2..7607584 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ composer require kaopur/yii2-doc-online ``` 'modules' => [ 'doconline' => [ + 'item' => 'app',//app、frontend、backend 'class' => 'Kaopur\yii2_doc_online\Module', 'defaultRoute' => 'index', //默认控制器 'appControllers' => true, //是否检测app\controllers命名空间下的控制器 diff --git a/src/ApiDesc.php b/src/ApiDesc.php index 40a5f6b..85c632f 100644 --- a/src/ApiDesc.php +++ b/src/ApiDesc.php @@ -35,14 +35,15 @@ public function render() { $exceptions = array(); $exploade_service = explode('/', $service); + $item = \Yii::$app->modules['doconline']->item; switch (count($exploade_service)) { case 2: - $classNameTpl = '\\app\\controllers\\%sController'; + $classNameTpl = "\\$item\\controllers\\%sController"; $className = sprintf($classNameTpl, ucfirst($exploade_service[0])); $methodName = 'action' .ucfirst($exploade_service[1]); break; case 3: - $classNameTpl = '\\app\\modules\\%s\\controllers\\%sController'; + $classNameTpl = "\\$item\\modules\\%s\\controllers\\%sController"; $className = sprintf($classNameTpl, $exploade_service[0], ucfirst($exploade_service[1])); $methodName = 'action' .ucfirst($exploade_service[2]); break; diff --git a/src/ApiList.php b/src/ApiList.php index b2a84ce..6cc30ee 100644 --- a/src/ApiList.php +++ b/src/ApiList.php @@ -36,7 +36,8 @@ public function render($modules = []) { if ($this->appControllers) { $files = listDir(API_ROOT . D_S . $apiDirName); $classesName = array_map(function($file){ - $classNameTemp = '/app' . rtrim(strstr($file, '/controllers/'), '.php'); + $item = \Yii::$app->modules['doconline']->item; + $classNameTemp = "/$item" . rtrim(strstr($file, '/controllers/'), '.php'); $className = str_replace('/', '\\', $classNameTemp); return $className; }, $files); @@ -46,7 +47,8 @@ public function render($modules = []) { $moduleDirName = '../modules/' . $module . '/controllers'; $moduleFiles = listDir(API_ROOT . D_S . $moduleDirName); return array_map(function($moduleFile) use ($module) { - $namespace = '\\app\\modules\\%s\\controllers\\%s'; + $item = \Yii::$app->modules['doconline']->item; + $namespace = "\\$item\\modules\\%s\\controllers\\%s"; $className = rtrim(substr($moduleFile, strrpos($moduleFile, D_S) + 1), '.php'); return sprintf($namespace, $module, $className); }, $moduleFiles); @@ -85,7 +87,7 @@ public function render($modules = []) { $docComment = $ref->getDocComment(); if ($docComment !== false) { $docCommentArr = explode("\n", $docComment); - $comment = isset($docCommentArr[1])?trim($docCommentArr[1]):''; + $comment = trim($docCommentArr[1]); $title = trim(substr($comment, strpos($comment, '*') + 1)); foreach ($docCommentArr as $comment) { $pos = stripos($comment, '@desc'); diff --git a/src/Module.php b/src/Module.php index fe9238b..4bab4d2 100644 --- a/src/Module.php +++ b/src/Module.php @@ -9,6 +9,7 @@ class Module extends \yii\base\Module public $suffix = ''; public $prefix = ''; public $modules = []; + public $item = 'app'; public function init() { parent::init();