Skip to content

Commit

Permalink
接口参数支持table指定表字段解析
Browse files Browse the repository at this point in the history
  • Loading branch information
HGthecode committed May 8, 2023
1 parent 5bab05f commit c8056cd
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/annotation/AddField.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class AddField extends ParamBase
* @param string $desc 字段名称
* @param bool $require 是否必须
* @param string $ref 引用注解/模型
* @param string $table 引用数据表
* @param string $md Md文本内容
* @param string $field 指定Ref引入的字段
* @param string $withoutField 排除Ref引入的字段
Expand All @@ -70,6 +71,7 @@ public function __construct(
string $desc = '',
bool $require = false,
$ref = "",
$table = "",
string $md = "",
$field = "",
$withoutField = "",
Expand Down
2 changes: 2 additions & 0 deletions src/annotation/Param.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Param extends ParamBase
* @param bool $require 是否必须
* @param string|int|bool $default 默认值
* @param string|array $ref 引用注解/模型
* @param string $table 引用数据表
* @param string|array $field 指定Ref引入的字段
* @param string|array $withoutField 排除Ref引入的字段
* @param string $desc 字段名称
Expand All @@ -41,6 +42,7 @@ public function __construct(
bool $require = false,
$default = "",
$ref = "",
$table = "",
$field = "",
$withoutField = "",
string $desc = '',
Expand Down
2 changes: 2 additions & 0 deletions src/annotation/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ final class Query extends ParamBase
* @param bool $require 是否必须
* @param string|int|bool $default 默认值
* @param string|array $ref 引用注解/模型
* @param string $table 引用数据表
* @param string|array $field 指定Ref引入的字段
* @param string|array $withoutField 排除Ref引入的字段
* @param string $desc 字段名称
Expand All @@ -42,6 +43,7 @@ public function __construct(
bool $require = false,
$default = "",
$ref = "",
$table = "",
$field = "",
$withoutField = "",
string $desc = '',
Expand Down
2 changes: 2 additions & 0 deletions src/annotation/Returned.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Returned extends ParamBase
* @param bool $require 是否必须
* @param string|int|bool $default 默认值
* @param string|array $ref 引用注解/模型
* @param string $table 引用数据表
* @param string|array $field 指定Ref引入的字段
* @param string|array $withoutField 排除Ref引入的字段
* @param string $desc 字段名称
Expand All @@ -42,6 +43,7 @@ public function __construct(
bool $require = false,
$default = "",
$ref = "",
$table = "",
$field = "",
$withoutField = "",
string $desc = '',
Expand Down
5 changes: 4 additions & 1 deletion src/parses/ParseApiDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,10 @@ protected function handleAnnotationsParamItem($param,$field){
}else{
return false;
}
}else{
}else if(!empty($param['table'])){
$tableParams = (new ParseModel($this->config))->getTableDocument($param['table'],[]);
$data = $this->handleRefData($param,$tableParams,$field);
} else{
$data = $param;
}
if (!empty($data['desc'])){
Expand Down
16 changes: 8 additions & 8 deletions src/parses/ParseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ public function parseModelTable($model,$classReflect,$methodName=""){
try {
// 获取所有模型属性
$propertys = $classReflect->getDefaultProperties();
$table =$this->getTableDocument($model, $propertys);
$tableName = $model->getTable();
$configTablePrefix = !empty($config['database']) && !empty($config['database']['prefix'])?$config['database']['prefix']:"";
if (!empty($configTablePrefix) && strpos($tableName, $configTablePrefix) === false){
$tableName = $configTablePrefix.$model->getTable();
}
$table =$this->getTableDocument($tableName, $propertys);
if (empty($methodName)){
return $table;
}
Expand Down Expand Up @@ -101,22 +106,17 @@ public static function getModelClass($namespaceName)

/**
* 获取模型注解数据
* @param $model
* @param $tableName
* @param $propertys
* @return array
*/
protected function getTableDocument($model,array $propertys):array
public function getTableDocument($tableName,array $propertys):array
{
$config = $this->config;
$fieldComment = [];
if (empty($config['database_query_function'])){
throw new ErrorException("not datatable_query_function config");
}
$tableName = $model->getTable();
$configTablePrefix = !empty($config['database']) && !empty($config['database']['prefix'])?$config['database']['prefix']:"";
if (!empty($configTablePrefix) && strpos($tableName, $configTablePrefix) === false){
$tableName = $configTablePrefix.$model->getTable();
}
$tableColumns = $config['database_query_function']("SHOW FULL COLUMNS FROM " . $tableName);
foreach ($tableColumns as $columns) {
$columns = Helper::objectToArray($columns);
Expand Down

0 comments on commit c8056cd

Please sign in to comment.