添加测试目录,仅供参考

This commit is contained in:
IT小强xqitw.cn 2018-06-06 13:41:31 +08:00
parent 603bd637bf
commit 5781e68d6e
5 changed files with 221 additions and 2 deletions

1
.gitignore vendored
View File

@ -1,4 +1,3 @@
/.idea
/test/
/vendor/
/composer.lock

View File

@ -40,4 +40,5 @@ $doc = $api->getApiDoc();
echo '<pre>';
var_dump($doc);
echo '</pre>';
```
```
+ 具体使用可参见test目录

38
test/Api.php Normal file
View File

@ -0,0 +1,38 @@
<?php
/**
* ==================================================================
* : Api.php
* :
* : IT小强
* 创建时间: 2018/6/5 9:43
* 修改时间:
* copyright (c) 2016 - 2018 mail@xqitw.cn
* ==================================================================
*/
/**
* @title 测试用的API类
* Class Api
*/
class Api
{
/**
* @title 添加操作
* @url https://wwww.baidu.com
* @method POST
* @param array|string|bool id 用户ID null 必须
* @param array|string|bool id2 用户ID2 false 非必须
* @code 1 成功
* @code 2 失败
* @return int code 状态码(具体参见状态码说明)
* @return string msg 提示信息
* @return object data 返回的数据
*/
public function add() {
}
public function edit() {
}
}

49
test/Api2.php Normal file
View File

@ -0,0 +1,49 @@
<?php
/**
* ==================================================================
* : Api2.php
* :
* : IT小强
* 创建时间: 2018/6/6 9:17
* 修改时间:
* copyright (c) 2016 - 2018 mail@xqitw.cn
* ==================================================================
*/
/**
* @title 测试用的API类2
* Class Api
*/
class Api2
{
/**
* @title 添加操作
* @url https://wwww.baidu.com
* @method POST
* @param array|string|bool id 用户ID null 必须
* @param array|string|bool id2 用户ID2 false 非必须
* @code 1 成功
* @code 2 失败
* @return int code 状态码(具体参见状态码说明)
* @return string msg 提示信息
* @return object data 返回的数据
*/
public function addxx() {
}
/**
* @title 添加操作
* @url https://wwww.baidu.com
* @method POST
* @param array|string|bool id 用户ID null 必须
* @param array|string|bool id2 用户ID2 false 非必须
* @code 1 成功
* @code 2 失败
* @return int code 状态码(具体参见状态码说明)
* @return string msg 提示信息
* @return object data 返回的数据
*/
public function editcccc() {
}
}

132
test/index.php Normal file
View File

@ -0,0 +1,132 @@
<?php
/**
* ==================================================================
* : index.php
* : API文档 By Api-Doc-PHP
* : IT小强
* 创建时间: 2018/6/5 9:48
* 修改时间:
* copyright (c) 2016 - 2018 mail@xqitw.cn
* ==================================================================
*/
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/Api.php'; // 加载测试API类1
require_once __DIR__ . '/Api2.php'; // 加载测试API类2
$config = [
'class' => ['Api', 'Api2'], // 要生成文档的类
'filter_method' => ['__construct'], // 要过滤的方法名称
];
$api = new \itxq\apidoc\ApiDoc($config);
$doc = $api->getApiDoc();
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<!-- 禁止浏览器初始缩放 -->
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, maximum-scale=1, user-scalable=0">
<title>API文档 By Api-Doc-PHP</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
.class-item .class-title {
text-indent: 0.6em;
border-left: 5px solid lightseagreen;
font-size: 24px;
margin: 10px 0;
}
.action-item .action-title {
text-indent: 0.6em;
border-left: 3px solid #F0AD4E;
font-size: 20px;
margin: 8px 0;
}
.table-item {
background-color: #F1F1F1;
padding-top: 10px;
}
</style>
</head>
<body>
<div class="container">
<?php foreach ($doc as $className => $classItem) { ?>
<div class="row">
<div class="class-item col-md-12" id="<?php echo $className; ?>">
<h2 class="class-title">
<?php echo $classItem['title']; ?>
</h2>
<hr>
<?php foreach ($classItem['action'] as $actionName => $actionItem) { ?>
<div class="action-item col-md-12" id="<?php echo $className; ?>-<?php echo $actionName; ?>">
<h4 class="action-title">API - <?php echo $actionItem['title']; ?></h4>
<p>请求方式:
<span class="btn btn-info btn-sm"><?php echo $actionItem['method']; ?></span>
</p>
<p>请求地址:<a href="<?php echo $actionItem['url']; ?>"><?php echo $actionItem['url']; ?></a></p>
<div class="table-item col-md-12">
<p class="table-title"><span class="btn btn-sm btn-danger">body参数</span></p>
<table class="table">
<tr>
<td>参数</td>
<td>类型</td>
<td>描述</td>
<td>默认值</td>
<td>是否必须</td>
</tr>
<?php foreach ($actionItem['param'] as $param) { ?>
<tr>
<td><?php echo $param['param_name']; ?></td>
<td><?php echo $param['param_type']; ?></td>
<td><?php echo $param['param_title']; ?></td>
<td><?php echo $param['param_default']; ?></td>
<td><?php echo $param['param_require']; ?></td>
</tr>
<?php } ?>
</table>
</div>
<div class="table-item col-md-12">
<p class="table-title"><span class="btn btn-sm btn-warning">状态码说明</span></p>
<table class="table">
<tr>
<td>状态码</td>
<td>描述</td>
</tr>
<?php foreach ($actionItem['code'] as $code) { ?>
<tr>
<td><?php echo $code['code']; ?></td>
<td><?php echo $code['content']; ?></td>
</tr>
<?php } ?>
</table>
</div>
<div class="table-item col-md-12">
<p class="table-title"><span class="btn btn-sm btn-success">返回参数</span></p>
<table class="table">
<tr>
<td>参数</td>
<td>类型</td>
<td>描述</td>
</tr>
<?php foreach ($actionItem['return'] as $return) { ?>
<tr>
<td><?php echo $return['return_name']; ?></td>
<td><?php echo $return['return_type']; ?></td>
<td><?php echo $return['return_title']; ?></td>
</tr>
<?php } ?>
</table>
</div>
</div>
<?php } ?>
</div>
</div>
<?php } ?>
</div>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js" type="text/javascript"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" type="text/javascript"></script>
</body>
</html>