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

Commit

Permalink
edit item
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaochengfu committed Sep 30, 2017
1 parent 882f79b commit b7b9a86
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .idea/dictionaries/fx2.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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命名空间下的控制器
Expand Down
5 changes: 3 additions & 2 deletions src/ApiDesc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions src/ApiList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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');
Expand Down
1 change: 1 addition & 0 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Module extends \yii\base\Module
public $suffix = '';
public $prefix = '';
public $modules = [];
public $item = 'app';
public function init()
{
parent::init();
Expand Down

0 comments on commit b7b9a86

Please sign in to comment.