1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Classes\Db; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Colunas dos bancos |
7
|
|
|
* |
8
|
|
|
* @author Pedro Alarcao <[email protected]> |
9
|
|
|
* @link https://github.com/pedro151/ORM-Generator |
10
|
|
|
*/ |
11
|
|
|
class Column |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Colunas dos bancos |
16
|
|
|
* |
17
|
|
|
* @author Pedro Alarcao <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
public function __construct () |
20
|
|
|
{ |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private $name; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var \Classes\Db\Constrant[] |
30
|
|
|
*/ |
31
|
|
|
private $primarykey; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
private $type; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
private $comment; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var boolean |
45
|
|
|
*/ |
46
|
|
|
private $nullable; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var int |
50
|
|
|
*/ |
51
|
|
|
private $max_length; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var \Classes\Db\Constrant[] |
55
|
|
|
*/ |
56
|
|
|
private $dependences; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var \Classes\Db\Constrant |
60
|
|
|
*/ |
61
|
|
|
private $refForeingkey; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @type string |
65
|
|
|
*/ |
66
|
|
|
private $sequence; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
public function getName () |
72
|
|
|
{ |
73
|
|
|
return $this->name; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* popula o |
78
|
|
|
* |
79
|
|
|
* @param $array |
80
|
|
|
*/ |
81
|
|
|
public function populate ( $array ) |
82
|
|
|
{ |
83
|
|
|
$this->name = $array[ 'name' ]; |
84
|
|
|
$this->type = $array[ 'type' ]; |
85
|
|
|
$this->nullable = $array[ 'nullable' ]; |
86
|
|
|
$this->max_length = $array[ 'max_length' ]; |
87
|
|
|
|
88
|
|
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return boolean |
93
|
|
|
*/ |
94
|
|
|
public function isPrimaryKey () |
95
|
|
|
{ |
96
|
|
|
return ! empty( $this->primarykey ); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return boolean |
101
|
|
|
*/ |
102
|
|
|
public function isForeingkey () |
103
|
|
|
{ |
104
|
|
|
return ! empty( $this->refForeingkey ); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return boolean |
109
|
|
|
*/ |
110
|
|
|
public function hasDependence () |
111
|
|
|
{ |
112
|
|
|
return ! empty( $this->dependences ); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return string |
117
|
|
|
*/ |
118
|
|
|
public function getType () |
119
|
|
|
{ |
120
|
|
|
return $this->type; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
|
|
public function getComment () |
127
|
|
|
{ |
128
|
|
|
return $this->comment; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @param string $comment |
133
|
|
|
*/ |
134
|
|
|
public function setComment ( $comment ) |
135
|
|
|
{ |
136
|
|
|
$this->comment = $comment; |
137
|
|
|
|
138
|
|
|
return $this; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @param \Classes\Db\Constrant $primarykey |
143
|
|
|
*/ |
144
|
|
|
public function setPrimaryKey ( Constrant $primarykey ) |
145
|
|
|
{ |
146
|
|
|
$this->primarykey = $primarykey; |
|
|
|
|
147
|
|
|
|
148
|
|
|
return $this; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @param \Classes\Db\Constrant $dependece |
153
|
|
|
*/ |
154
|
|
|
public function addDependece ( Constrant $dependece ) |
155
|
|
|
{ |
156
|
|
|
$this->dependences[] = $dependece; |
157
|
|
|
|
158
|
|
|
return $this; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @param $constraint_name |
163
|
|
|
* @param $table_name |
164
|
|
|
* @param $column_name |
165
|
|
|
* |
166
|
|
|
* @return $this |
167
|
|
|
*/ |
168
|
|
|
public function createDependece ( $constraint_name , $table_name , $column_name , $schema = null ) |
169
|
|
|
{ |
170
|
|
|
$objConstrantDependence = new Constrant(); |
171
|
|
|
$objConstrantDependence->populate ( |
172
|
|
|
array ( |
173
|
|
|
'constrant' => $constraint_name , |
174
|
|
|
'schema' => $schema , |
175
|
|
|
'table' => $table_name , |
176
|
|
|
'column' => $column_name |
177
|
|
|
) |
178
|
|
|
); |
179
|
|
|
|
180
|
|
|
$this->addDependece ( $objConstrantDependence ); |
181
|
|
|
|
182
|
|
|
return $this; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @param \Classes\Db\Constrant $reference |
187
|
|
|
*/ |
188
|
|
|
public function addRefFk ( Constrant $reference ) |
189
|
|
|
{ |
190
|
|
|
$this->refForeingkey = $reference; |
191
|
|
|
|
192
|
|
|
return $this; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* retorna as foreingkeys |
197
|
|
|
* |
198
|
|
|
* @return \Classes\Db\Constrant |
199
|
|
|
*/ |
200
|
|
|
public function getFks () |
201
|
|
|
{ |
202
|
|
|
return $this->refForeingkey; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* Retorna as dependencias da tabela |
207
|
|
|
* |
208
|
|
|
* @return \Classes\Db\Constrant[] |
209
|
|
|
*/ |
210
|
|
|
public function getDependences () |
211
|
|
|
{ |
212
|
|
|
return $this->dependences; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @return bool |
217
|
|
|
*/ |
218
|
|
|
public function hasDependences () |
219
|
|
|
{ |
220
|
|
|
return (bool) count ( $this->dependences ); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* Retorna a constrant da primarykey da tabela |
225
|
|
|
* |
226
|
|
|
* @return \Classes\Db\Constrant[] |
227
|
|
|
*/ |
228
|
|
|
public function getPrimaryKey () |
229
|
|
|
{ |
230
|
|
|
return $this->primarykey; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* |
235
|
|
|
*/ |
236
|
|
|
public function getMaxLength () |
237
|
|
|
{ |
238
|
|
|
return $this->max_length; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* @return bool |
243
|
|
|
*/ |
244
|
|
|
public function hasSequence () |
245
|
|
|
{ |
246
|
|
|
return (bool) $this->sequence; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* @return string |
251
|
|
|
*/ |
252
|
|
|
public function getSequence () |
253
|
|
|
{ |
254
|
|
|
return $this->sequence; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* @param string $sequence |
259
|
|
|
*/ |
260
|
|
|
public function setSequence ( $sequence ) |
261
|
|
|
{ |
262
|
|
|
$this->sequence = $sequence; |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* @return boolean |
267
|
|
|
*/ |
268
|
|
|
public function isNullable () |
269
|
|
|
{ |
270
|
|
|
return $this->nullable; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
} |
274
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..