forked from kuafuRace/phprap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathField.php
More file actions
167 lines (148 loc) · 3.87 KB
/
Copy pathField.php
File metadata and controls
167 lines (148 loc) · 3.87 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "doc_field".
*
* @property int $id
* @property string $encode_id 加密id
* @property int $api_id 接口ID
* @property string $header_fields header字段
* @property string $request_fields 请求字段
* @property string $response_fields 响应字段
* @property int $creater_id 创建者id
* @property int $updater_id 更新者id
* @property string $created_at 创建时间
* @property string $updated_at 更新时间
*/
class Field extends Model
{
/**
* 字段类型标签
* @var array
*/
public $fieldTypeLabels = [
'string' => '字符串',
'integer' => '整数',
'float' => '小数',
'boolean' => '布尔',
'object' => '对象',
'array' => '数组',
];
/**
* 是否必须标签
* @var array
*/
public $requiredLabels = [
'10' => '是',
'20' => '否',
];
/**
* 默认header参数
* @var array
*/
public $defaultHeaderParams = [
'Accept','Accept-Charset','Accept-Encoding','Accept-Language','Accept-Datetime','Accept-Ranges','Authorization',
'Cache-Control','Connection','Cookie','Content-Disposition','Content-Length','Content-Type','Content-MD5',
'Referer',
'User-Agent',
'X-Requested-With','X-Forwarded-For','X-Forwarded-Host','X-Csrf-Token'
];
/**
* 指定数据表
*/
public static function tableName()
{
return '{{%field}}';
}
/**
* 验证规则
* @return array
*/
public function rules()
{
return [
[['api_id', 'creater_id', 'updater_id'], 'integer'],
[['creater_id', 'created_at'], 'required'],
[['header_fields', 'request_fields', 'response_fields'], 'string'],
[['encode_id'], 'unique'],
[['created_at', 'updated_at'], 'safe'],
];
}
/**
* 字段字典
* @return array
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'api_id' => '接口ID',
'header_fields' => 'header字段',
'request_fields' => '请求字段',
'response_fields' => '响应字段',
'creater_id' => '创建者id',
'updater_id' => '更新者id',
'created_at' => '创建时间',
'updated_at' => '更新时间',
];
}
/**
* 判断字段是否是复合类型
* @param $field
* @return bool
*/
public function isCompositeType($type)
{
return in_array($type, ['array', 'object']) ? true : false;
}
/**
* 获取所属接口
* @return \yii\db\ActiveQuery
*/
public function getApi()
{
return $this->hasOne(Api::className(),['id'=>'api_id']);
}
/**
* 获取header数组
* @return array
*/
public function getHeaderAttributes()
{
return json_decode($this->header_fields);
}
/**
* 获取请求参数数组
* @return array
*/
public function getRequestAttributes()
{
return json_decode($this->request_fields);
}
/**
* 获取响应参数数组
* @return array
*/
public function getResponseAttributes()
{
return json_decode($this->response_fields);
}
/**
* 获取更新内容
* @return string
*/
public function getUpdateContent()
{
$content = '';
foreach (array_filter($this->dirtyAttributes) as $name => $value) {
$label = '<code>' . $this->getAttributeLabel($name) . '</code>';
if(isset($this->oldAttributes[$name])){
$content .= '更新了 ' . $label . ',';
}else{
$content .= '添加了 ' . $label . ',';
}
}
return trim($content, ',');
}
}