|
1
|
|
|
<?php |
|
2
|
|
|
// +---------------------------------------------------------------------- |
|
3
|
|
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ] |
|
4
|
|
|
// +---------------------------------------------------------------------- |
|
5
|
|
|
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved. |
|
6
|
|
|
// +---------------------------------------------------------------------- |
|
7
|
|
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) |
|
8
|
|
|
// +---------------------------------------------------------------------- |
|
9
|
|
|
// | Author: liu21st <[email protected]> |
|
10
|
|
|
// +---------------------------------------------------------------------- |
|
11
|
|
|
declare (strict_types = 1); |
|
12
|
|
|
|
|
13
|
|
|
namespace think\db\concern; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* 数据字段信息 |
|
17
|
|
|
*/ |
|
18
|
|
|
trait TableFieldInfo |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* 获取数据表字段信息 |
|
23
|
|
|
* @access public |
|
24
|
|
|
* @param string $tableName 数据表名 |
|
25
|
|
|
* @return array |
|
26
|
|
|
*/ |
|
27
|
|
|
public function getTableFields($tableName = ''): array |
|
28
|
|
|
{ |
|
29
|
|
|
if ('' == $tableName) { |
|
30
|
|
|
$tableName = $this->getTable(); |
|
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
return $this->connection->getTableFields($tableName); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* 设置字段类型信息 |
|
38
|
|
|
* @access public |
|
39
|
|
|
* @param array $type 字段类型信息 |
|
40
|
|
|
* @return $this |
|
41
|
|
|
*/ |
|
42
|
|
|
public function setFieldType(array $type) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->options['field_type'] = $type; |
|
|
|
|
|
|
45
|
|
|
return $this; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* 获取详细字段类型信息 |
|
50
|
|
|
* @access public |
|
51
|
|
|
* @param string $tableName 数据表名称 |
|
52
|
|
|
* @return array |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getFields(string $tableName = ''): array |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->connection->getFields($tableName ?: $this->getTable()); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* 获取字段类型信息 |
|
61
|
|
|
* @access public |
|
62
|
|
|
* @return array |
|
63
|
|
|
*/ |
|
64
|
|
|
public function getFieldsType(): array |
|
65
|
|
|
{ |
|
66
|
|
|
if (!empty($this->options['field_type'])) { |
|
67
|
|
|
return $this->options['field_type']; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return $this->connection->getFieldsType($this->getTable()); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* 获取字段类型信息 |
|
75
|
|
|
* @access public |
|
76
|
|
|
* @param string $field 字段名 |
|
77
|
|
|
* @return string|null |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getFieldType(string $field) |
|
80
|
|
|
{ |
|
81
|
|
|
$fieldType = $this->getFieldsType(); |
|
82
|
|
|
|
|
83
|
|
|
return $fieldType[$field] ?? null; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* 获取字段类型信息 |
|
88
|
|
|
* @access public |
|
89
|
|
|
* @return array |
|
90
|
|
|
*/ |
|
91
|
|
|
public function getFieldsBindType(): array |
|
92
|
|
|
{ |
|
93
|
|
|
$fieldType = $this->getFieldsType(); |
|
94
|
|
|
|
|
95
|
|
|
return array_map([$this->connection, 'getFieldBindType'], $fieldType); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* 获取字段类型信息 |
|
100
|
|
|
* @access public |
|
101
|
|
|
* @param string $field 字段名 |
|
102
|
|
|
* @return int |
|
103
|
|
|
*/ |
|
104
|
|
|
public function getFieldBindType(string $field): int |
|
105
|
|
|
{ |
|
106
|
|
|
$fieldType = $this->getFieldType($field); |
|
107
|
|
|
|
|
108
|
|
|
return $this->connection->getFieldBindType($fieldType ?: ''); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
} |
|
112
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.