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] 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();