1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Lagdo\DbAdmin\Driver; |
4
|
|
|
|
5
|
|
|
use Lagdo\DbAdmin\Driver\Db\TableInterface; |
6
|
|
|
use Lagdo\DbAdmin\Driver\Entity\TableEntity; |
7
|
|
|
use Lagdo\DbAdmin\Driver\Entity\TriggerEntity; |
8
|
|
|
|
9
|
|
|
trait TableTrait |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var TableInterface |
13
|
|
|
*/ |
14
|
|
|
protected $table; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Get table status |
18
|
|
|
* |
19
|
|
|
* @param string $table |
20
|
|
|
* @param bool $fast Return only "Name", "Engine" and "Comment" fields |
21
|
|
|
* |
22
|
|
|
* @return TableEntity|null |
23
|
|
|
*/ |
24
|
|
|
public function tableStatus(string $table, bool $fast = false) |
25
|
|
|
{ |
26
|
|
|
return $this->table->tableStatus($table, $fast); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Get all tables statuses |
31
|
|
|
* |
32
|
|
|
* @param bool $fast Return only "Name", "Engine" and "Comment" fields |
33
|
|
|
* |
34
|
|
|
* @return TableEntity[] |
35
|
|
|
*/ |
36
|
|
|
public function tableStatuses(bool $fast = false) |
37
|
|
|
{ |
38
|
|
|
return $this->table->tableStatuses($fast); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Get all tables names |
43
|
|
|
* |
44
|
|
|
* @return array |
45
|
|
|
*/ |
46
|
|
|
public function tableNames() |
47
|
|
|
{ |
48
|
|
|
return $this->table->tableNames(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Get status of a single table and fall back to name on error |
53
|
|
|
* |
54
|
|
|
* @param string $table |
55
|
|
|
* @param bool $fast Return only "Name", "Engine" and "Comment" fields |
56
|
|
|
* |
57
|
|
|
* @return TableEntity |
58
|
|
|
*/ |
59
|
|
|
public function tableStatusOrName(string $table, bool $fast = false) |
60
|
|
|
{ |
61
|
|
|
return $this->table->tableStatusOrName($table, $fast); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Find out whether the identifier is view |
66
|
|
|
* |
67
|
|
|
* @param TableEntity $tableStatus |
68
|
|
|
* |
69
|
|
|
* @return bool |
70
|
|
|
*/ |
71
|
|
|
public function isView(TableEntity $tableStatus) |
72
|
|
|
{ |
73
|
|
|
return $this->table->isView($tableStatus); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Check if table supports foreign keys |
78
|
|
|
* |
79
|
|
|
* @param TableEntity $tableStatus |
80
|
|
|
* |
81
|
|
|
* @return bool |
82
|
|
|
*/ |
83
|
|
|
public function supportForeignKeys(TableEntity $tableStatus) |
84
|
|
|
{ |
85
|
|
|
return $this->table->supportForeignKeys($tableStatus); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Get information about fields |
90
|
|
|
* |
91
|
|
|
* @param string $table |
92
|
|
|
* |
93
|
|
|
* @return array |
94
|
|
|
*/ |
95
|
|
|
public function fields(string $table) |
96
|
|
|
{ |
97
|
|
|
return $this->table->fields($table); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Get table indexes |
102
|
|
|
* |
103
|
|
|
* @param string $table |
104
|
|
|
* |
105
|
|
|
* @return array |
106
|
|
|
*/ |
107
|
|
|
public function indexes(string $table) |
108
|
|
|
{ |
109
|
|
|
return $this->table->indexes($table); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Get foreign keys in table |
114
|
|
|
* |
115
|
|
|
* @param string $table |
116
|
|
|
* |
117
|
|
|
* @return array array($name => array("db" => , "ns" => , "table" => , "source" => [], "target" => [], "onDelete" => , "onUpdate" => )) |
118
|
|
|
*/ |
119
|
|
|
public function foreignKeys(string $table) |
120
|
|
|
{ |
121
|
|
|
return $this->table->foreignKeys($table); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Get information about a trigger |
126
|
|
|
* |
127
|
|
|
* @param string $name |
128
|
|
|
* @param string $table |
129
|
|
|
* |
130
|
|
|
* @return TriggerEntity |
131
|
|
|
*/ |
132
|
|
|
public function trigger(string $name, string $table = '') |
133
|
|
|
{ |
134
|
|
|
return $this->table->trigger($name, $table); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Get defined triggers |
139
|
|
|
* |
140
|
|
|
* @param string $table |
141
|
|
|
* |
142
|
|
|
* @return array |
143
|
|
|
*/ |
144
|
|
|
public function triggers(string $table) |
145
|
|
|
{ |
146
|
|
|
return $this->table->triggers($table); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Get trigger options |
151
|
|
|
* |
152
|
|
|
* @return array ("Timing" => [], "Event" => [], "Type" => []) |
153
|
|
|
*/ |
154
|
|
|
public function triggerOptions() |
155
|
|
|
{ |
156
|
|
|
return $this->table->triggerOptions(); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Get referencable tables with single column primary key except self |
161
|
|
|
* |
162
|
|
|
* @param string $table |
163
|
|
|
* |
164
|
|
|
* @return array |
165
|
|
|
*/ |
166
|
|
|
public function referencableTables(string $table) |
167
|
|
|
{ |
168
|
|
|
return $this->table->referencableTables($table); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Get help link for table |
173
|
|
|
* |
174
|
|
|
* @param string $name |
175
|
|
|
* |
176
|
|
|
* @return string relative URL or null |
177
|
|
|
*/ |
178
|
|
|
public function tableHelp(string $name) |
179
|
|
|
{ |
180
|
|
|
return $this->table->tableHelp($name); |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|