DocController.class.php
1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* 主页
*/
namespace Frontend\Controller\Index;
use Common\Common\ApiDoc;
use Common\Service\MethodService;
class DocController extends AbstractController
{
/**
* @return bool
*/
public function Index()
{
$method = I('get.method');
if (empty($method)) {
die('缺少参数: method');
}
$file = I('get.file');
$methodService = new MethodService();
$fileData = $methodService->makeFile($file);
list($className, $methodName) = explode('.', $method);
// 包含文件
$fileMethods = @include_once($fileData['fileName']);
// 通过类名获取方面数据
$methodService->getMethodData($fileData['className'], $file, $fileMethods);
// 获取返回结果
$rMethod = new \ReflectionMethod($className, $methodName);
$docComment = $rMethod->getDocComment();
// 解析注释
$comments = ApiDoc::instance()->parseComment($docComment);
// 生成返回数据格式
$returnExample = array(
'errcode' => 0,
'errmsg' => 'ok',
'requestId' => '',
'errsdkcode' => '',
'timestamp' => NOW_TIME,
'result' => ApiDoc::instance()->createParamExample($comments['return'])
);
$paramExample = ApiDoc::instance()->createParamExample($comments['param']);
$this->assign('comments', $comments);
$this->assign('paramExample', var_export($paramExample, true));
$this->assign('paramJson', rjson_encode($paramExample, JSON_PRETTY_PRINT));
$this->assign('returnExample', var_export($returnExample, true));
$this->assign('returnJson', rjson_encode($returnExample, JSON_PRETTY_PRINT));
$this->assign('method', $method);
$this->assign('file', $file);
$this->assign('apiUrl', $methodService->file2api($file, $methodName));
$this->_output('Index/Doc');
return true;
}
}