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