From b7b9a865d6f005e4076ca55844f03fb04023eb6f Mon Sep 17 00:00:00 2001 From: xiaochengfu <1033426413@qq.com> Date: Sat, 30 Sep 2017 18:26:18 +0800 Subject: [PATCH 1/2] edit item --- .idea/dictionaries/fx2.xml | 3 +++ .idea/vcs.xml | 6 ++++++ README.md | 1 + src/ApiDesc.php | 5 +++-- src/ApiList.php | 8 +++++--- src/Module.php | 1 + 6 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 .idea/dictionaries/fx2.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/dictionaries/fx2.xml b/.idea/dictionaries/fx2.xml new file mode 100644 index 0000000..f3f8e9d --- /dev/null +++ b/.idea/dictionaries/fx2.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 3b4b7a2..756480c 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ composer require kaopur/yii2-doc-online ``` 'modules' => [ 'doconline' => [ + 'item' => 'frontend', '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(); From 1e1a94568d54a696b1db572b721c9c4bb83d0098 Mon Sep 17 00:00:00 2001 From: xiaochengfu <1033426413@qq.com> Date: Mon, 9 Oct 2017 14:14:05 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=AB=98=E7=BA=A7?= =?UTF-8?q?=E7=89=88=E7=9A=84=E7=9B=AE=E5=BD=95=E6=8C=87=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/dictionaries/fx2.xml | 3 --- .idea/vcs.xml | 6 ------ README.md | 2 +- 3 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 .idea/dictionaries/fx2.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/dictionaries/fx2.xml b/.idea/dictionaries/fx2.xml deleted file mode 100644 index f3f8e9d..0000000 --- a/.idea/dictionaries/fx2.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/README.md b/README.md index 756480c..7607584 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ composer require kaopur/yii2-doc-online ``` 'modules' => [ 'doconline' => [ - 'item' => 'frontend', + 'item' => 'app',//app、frontend、backend 'class' => 'Kaopur\yii2_doc_online\Module', 'defaultRoute' => 'index', //默认控制器 'appControllers' => true, //是否检测app\controllers命名空间下的控制器