...
|
...
|
@@ -3,24 +3,25 @@ namespace Api\Doc; |
|
|
|
|
|
class Doc
|
|
|
{
|
|
|
protected $config = [
|
|
|
'title'=>'APi接口文档',
|
|
|
'version'=>'1.0.0',
|
|
|
'copyright'=>'银河百荣科技',
|
|
|
protected $config = [
|
|
|
'title' => 'APi接口文档',
|
|
|
'version' => '1.0.0',
|
|
|
'copyright' => '银河百荣科技',
|
|
|
'controller' => [
|
|
|
'app\portal\controller\IndexController',
|
|
|
'app\escort\controller\EscortController',
|
|
|
'app\activity\controller\ActivityController'
|
|
|
'app\activity\controller\ActivityController',
|
|
|
'app\user\controller\CenterController'
|
|
|
],
|
|
|
'password'=>'bronet',
|
|
|
'static_path'=>'',
|
|
|
'filter_method'=>['_empty'],
|
|
|
'password' => 'bronet',
|
|
|
'static_path' => '',
|
|
|
'filter_method' => ['_empty'],
|
|
|
'return_format' => [
|
|
|
'code' => "状态码20000/40000+",
|
|
|
'msg' => "提示信息",
|
|
|
],
|
|
|
'public_header'=>[],
|
|
|
'public_param'=>[]
|
|
|
'public_header' => [],
|
|
|
'public_param' => []
|
|
|
];
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -47,7 +48,7 @@ class Doc |
|
|
/**
|
|
|
* 设置验证码配置
|
|
|
* @access public
|
|
|
* @param string $name 配置名称
|
|
|
* @param string $name 配置名称
|
|
|
* @param string $value 配置值
|
|
|
* @return void
|
|
|
*/
|
...
|
...
|
@@ -77,52 +78,48 @@ class Doc |
|
|
{
|
|
|
$controller = $this->config['controller'];
|
|
|
$list = [];
|
|
|
foreach ($controller as $class)
|
|
|
{
|
|
|
if(class_exists($class))
|
|
|
{
|
|
|
foreach ($controller as $class) {
|
|
|
if (class_exists($class)) {
|
|
|
$module = [];
|
|
|
$reflection = new \ReflectionClass($class);
|
|
|
$doc_str = $reflection->getDocComment();
|
|
|
$doc = new DocParser();
|
|
|
$class_doc = $doc->parse($doc_str);
|
|
|
$module = $class_doc;
|
|
|
$module = $class_doc;
|
|
|
$module['class'] = $class;
|
|
|
$method = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
|
|
|
$filter_method = array_merge(['__construct'], $this->config['filter_method']);
|
|
|
$module['actions'] = [];
|
|
|
foreach ($method as $action){
|
|
|
if(!in_array($action->name, $filter_method))
|
|
|
{
|
|
|
foreach ($method as $action) {
|
|
|
if (!in_array($action->name, $filter_method)) {
|
|
|
$doc = new DocParser();
|
|
|
$doc_str = $action->getDocComment();
|
|
|
if($doc_str)
|
|
|
{
|
|
|
if ($doc_str) {
|
|
|
$action_doc = $doc->parse($doc_str);
|
|
|
$action_doc['name'] = $class."::".$action->name;
|
|
|
if(array_key_exists('title', $action_doc)){
|
|
|
if(array_key_exists('module', $action_doc)){
|
|
|
$action_doc['name'] = $class . "::" . $action->name;
|
|
|
if (array_key_exists('title', $action_doc)) {
|
|
|
if (array_key_exists('module', $action_doc)) {
|
|
|
$key = array_search($action_doc['module'], array_column($module['actions'], 'title'));
|
|
|
if($key === false){
|
|
|
if ($key === false) {
|
|
|
$action = $module;
|
|
|
$action['title'] = $action_doc['module'];
|
|
|
$action['module'] = $action_doc['module'];
|
|
|
$action['actions'] = [];
|
|
|
array_push($action['actions'], $action_doc);
|
|
|
array_push($module['actions'], $action);
|
|
|
}else{
|
|
|
} else {
|
|
|
array_push($module['actions'][$key]['actions'], $action_doc);
|
|
|
}
|
|
|
}else{
|
|
|
} else {
|
|
|
array_push($module['actions'], $action_doc);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if(array_key_exists('group', $module)){
|
|
|
if (array_key_exists('group', $module)) {
|
|
|
$key = array_search($module['group'], array_column($list, 'title'));
|
|
|
if($key === false){ //创建分组
|
|
|
if ($key === false) { //创建分组
|
|
|
$floder = [
|
|
|
'title' => $module['group'],
|
|
|
'description' => '',
|
...
|
...
|
@@ -132,10 +129,10 @@ class Doc |
|
|
];
|
|
|
array_push($floder['actions'], $module);
|
|
|
array_push($list, $floder);
|
|
|
}else{
|
|
|
} else {
|
|
|
array_push($list[$key]['actions'], $module);
|
|
|
}
|
|
|
}else{
|
|
|
} else {
|
|
|
array_push($list, $module);
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -157,21 +154,19 @@ class Doc |
|
|
$doc_str = $reflection->getDocComment();
|
|
|
$doc = new DocParser();
|
|
|
$class_doc = $doc->parse($doc_str);
|
|
|
if(array_key_exists('group', $class_doc)){
|
|
|
if (array_key_exists('group', $class_doc)) {
|
|
|
$key = array_search($class_doc['group'], array_column($list, 'title'));
|
|
|
if($key === false){ //创建分组
|
|
|
if ($key === false) { //创建分组
|
|
|
$floder = [
|
|
|
'title' => $class_doc['group'],
|
|
|
'children' => []
|
|
|
];
|
|
|
array_push($floder['children'], $class_doc);
|
|
|
array_push($list, $floder);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
} else {
|
|
|
array_push($list[$key]['children'], $class_doc);
|
|
|
}
|
|
|
}else{
|
|
|
} else {
|
|
|
array_push($list, $class_doc);
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -188,18 +183,18 @@ class Doc |
|
|
public function getInfo($class, $action)
|
|
|
{
|
|
|
$action_doc = [];
|
|
|
if($class && class_exists($class)){
|
|
|
if ($class && class_exists($class)) {
|
|
|
$reflection = new \ReflectionClass($class);
|
|
|
$doc_str = $reflection->getDocComment();
|
|
|
$doc = new DocParser();
|
|
|
$class_doc = $doc->parse($doc_str);
|
|
|
$class_doc['header'] = isset($class_doc['header'])? $class_doc['header'] : [];
|
|
|
$class_doc['header'] = isset($class_doc['header']) ? $class_doc['header'] : [];
|
|
|
$class_doc['param'] = isset($class_doc['param']) ? $class_doc['param'] : [];
|
|
|
if($reflection->hasMethod($action)) {
|
|
|
if ($reflection->hasMethod($action)) {
|
|
|
$method = $reflection->getMethod($action);
|
|
|
$doc = new DocParser();
|
|
|
$action_doc = $doc->parse($method->getDocComment());
|
|
|
$action_doc['name'] = $class."::".$method->name;
|
|
|
$action_doc['name'] = $class . "::" . $method->name;
|
|
|
$action_doc['header'] = isset($action_doc['header']) ? array_merge($class_doc['header'], $action_doc['header']) : $class_doc['header'];
|
|
|
$action_doc['param'] = isset($action_doc['param']) ? array_merge($class_doc['param'], $action_doc['param']) : $class_doc['param'];
|
|
|
}
|
...
|
...
|
@@ -216,27 +211,22 @@ class Doc |
|
|
{
|
|
|
$controller = $this->config['controller'];
|
|
|
$list = [];
|
|
|
foreach ($controller as $class)
|
|
|
{
|
|
|
if(class_exists($class))
|
|
|
{
|
|
|
foreach ($controller as $class) {
|
|
|
if (class_exists($class)) {
|
|
|
$reflection = new \ReflectionClass($class);
|
|
|
$method = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
|
|
|
$filter_method = array_merge(['__construct'], $this->config['filter_method']);
|
|
|
foreach ($method as $action){
|
|
|
if(!in_array($action->name, $filter_method))
|
|
|
{
|
|
|
foreach ($method as $action) {
|
|
|
if (!in_array($action->name, $filter_method)) {
|
|
|
$doc = new DocParser();
|
|
|
$doc_str = $action->getDocComment();
|
|
|
if($doc_str)
|
|
|
{
|
|
|
if ($doc_str) {
|
|
|
$action_doc = $doc->parse($doc_str);
|
|
|
$action_doc['name'] = $class."::".$action->name;
|
|
|
if((isset($action_doc['title']) && strpos($action_doc['title'], $keyword) !== false)
|
|
|
|| (isset($action_doc['description']) && strpos($action_doc['description'], $keyword) !== false)
|
|
|
|| (isset($action_doc['author']) && strpos($action_doc['author'], $keyword) !== false)
|
|
|
|| (isset($action_doc['url']) && strpos($action_doc['url'], $keyword) !== false))
|
|
|
{
|
|
|
$action_doc['name'] = $class . "::" . $action->name;
|
|
|
if ((isset($action_doc['title']) && strpos($action_doc['title'], $keyword) !== false)
|
|
|
|| (isset($action_doc['description']) && strpos($action_doc['description'], $keyword) !== false)
|
|
|
|| (isset($action_doc['author']) && strpos($action_doc['author'], $keyword) !== false)
|
|
|
|| (isset($action_doc['url']) && strpos($action_doc['url'], $keyword) !== false)) {
|
|
|
array_push($list, $action_doc);
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -256,17 +246,16 @@ class Doc |
|
|
{
|
|
|
$json = '{<br>';
|
|
|
$data = $this->config['return_format'];
|
|
|
foreach ($data as $name=>$value) {
|
|
|
$json .= ' "'.$name.'":'.$value.',<br>';
|
|
|
foreach ($data as $name => $value) {
|
|
|
$json .= ' "' . $name . '":' . $value . ',<br>';
|
|
|
}
|
|
|
$json .= ' "data":{<br/>';
|
|
|
$returns = isset($doc['return']) ? $doc['return'] : [];
|
|
|
foreach ($returns as $val)
|
|
|
{
|
|
|
list($name, $value) = explode(":", trim($val));
|
|
|
if(strpos($value, '@') != false){
|
|
|
foreach ($returns as $val) {
|
|
|
list($name, $value) = explode(":", trim($val));
|
|
|
if (strpos($value, '@') != false) {
|
|
|
$json .= $this->string2jsonArray($doc, $val, ' ');
|
|
|
}else{
|
|
|
} else {
|
|
|
$json .= ' ' . $this->string2json(trim($name), $value);
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -281,11 +270,12 @@ class Doc |
|
|
* @param $val
|
|
|
* @return string
|
|
|
*/
|
|
|
private function string2json($name, $val){
|
|
|
if(strpos($val,'#') != false){
|
|
|
return '"'.$name.'": ["'.str_replace('#','',$val).'"],<br/>';
|
|
|
}else {
|
|
|
return '"'.$name.'":"'.$val.'",<br/>';
|
|
|
private function string2json($name, $val)
|
|
|
{
|
|
|
if (strpos($val, '#') != false) {
|
|
|
return '"' . $name . '": ["' . str_replace('#', '', $val) . '"],<br/>';
|
|
|
} else {
|
|
|
return '"' . $name . '":"' . $val . '",<br/>';
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -296,28 +286,29 @@ class Doc |
|
|
* @param $space
|
|
|
* @return string
|
|
|
*/
|
|
|
private function string2jsonArray($doc, $val, $space){
|
|
|
list($name, $value) = explode(":", trim($val));
|
|
|
private function string2jsonArray($doc, $val, $space)
|
|
|
{
|
|
|
list($name, $value) = explode(":", trim($val));
|
|
|
$json = "";
|
|
|
if(strpos($value, "@!") != false){
|
|
|
$json .= $space.'"'.$name.'":{//'.str_replace('@!','',$value).'<br/>';
|
|
|
}else{
|
|
|
$json .= $space.'"'.$name.'":[{//'.str_replace('@','',$value).'<br/>';
|
|
|
if (strpos($value, "@!") != false) {
|
|
|
$json .= $space . '"' . $name . '":{//' . str_replace('@!', '', $value) . '<br/>';
|
|
|
} else {
|
|
|
$json .= $space . '"' . $name . '":[{//' . str_replace('@', '', $value) . '<br/>';
|
|
|
}
|
|
|
$return = isset($doc[$name]) ? $doc[$name] : [];
|
|
|
if(preg_match_all('/(\w+):(.*?)[\s\n]/s', $return." ", $meatchs)){
|
|
|
foreach ($meatchs[0] as $key=>$v){
|
|
|
if(strpos($meatchs[2][$key],'@') != false){
|
|
|
$json .= $this->string2jsonArray($doc,$v,$space.' ');
|
|
|
} else{
|
|
|
$json .= $space.' '. $this->string2json(trim($meatchs[1][$key]), $meatchs[2][$key]);
|
|
|
if (preg_match_all('/(\w+):(.*?)[\s\n]/s', $return . " ", $meatchs)) {
|
|
|
foreach ($meatchs[0] as $key => $v) {
|
|
|
if (strpos($meatchs[2][$key], '@') != false) {
|
|
|
$json .= $this->string2jsonArray($doc, $v, $space . ' ');
|
|
|
} else {
|
|
|
$json .= $space . ' ' . $this->string2json(trim($meatchs[1][$key]), $meatchs[2][$key]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if(strpos($value, "@!") != false){
|
|
|
$json .= $space."}<br/>";
|
|
|
}else{
|
|
|
$json .= $space."}]<br/>";
|
|
|
if (strpos($value, "@!") != false) {
|
|
|
$json .= $space . "}<br/>";
|
|
|
} else {
|
|
|
$json .= $space . "}]<br/>";
|
|
|
}
|
|
|
return $json;
|
|
|
}
|
...
|
...
|
|