RefreshApiListController.class.php
1.45 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
<?php
/**
* 主页
*/
namespace Api\Controller\ApiDoc;
use Common\Common\FileSystem;
use Common\Service\MethodService;
use Think\Exception;
class RefreshApiListController extends AbstractController
{
/**
* @return bool
*/
public function Index()
{
$dir = I('get.dir');
if (empty($dir)) {
E('_ERR_DIR_IS_EMPTY');
return true;
}
// 错误提示
$errors = array();
$methodService = new MethodService();
// 清除缓存
$methodService->clearMethodCache($dir);
// 获取所有PHP文件列表
$files = FileSystem::instance()->scanFile($dir, 'php');
foreach ($files as $_file) {
try {
$fileData = $methodService->makeFile($_file);
// 包含文件
$fileMethods = @include_once($fileData['fileName']);
// 通过类名获取方面数据
$methodService->getMethodData($fileData['className'], $_file, $fileMethods);
} catch (Exception $e) {
// do nothing
if (cfg('SYNTAX_ERROR_CODE') == $e->getCode()) {
$errors[] = $e->getCode() . ':' . $e->getMessage() . "({$_file})";
}
}
}
// 如果解析出错了
if (!empty($errors)) {
E("2000:\n" . implode("\n", $errors));
return false;
}
return true;
}
}