|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\DBAL\Schema; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Types\Type; |
|
8
|
|
|
use const E_USER_DEPRECATED; |
|
9
|
|
|
use function array_merge; |
|
10
|
|
|
use function assert; |
|
11
|
|
|
use function is_string; |
|
12
|
|
|
use function method_exists; |
|
13
|
|
|
use function sprintf; |
|
14
|
|
|
use function trigger_error; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Object representation of a database column. |
|
18
|
|
|
*/ |
|
19
|
|
|
class Column extends AbstractAsset |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var Type */ |
|
22
|
|
|
protected $_type; |
|
23
|
|
|
|
|
24
|
|
|
/** @var int|null */ |
|
25
|
|
|
protected $_length; |
|
26
|
|
|
|
|
27
|
|
|
/** @var int */ |
|
28
|
|
|
protected $_precision; |
|
29
|
|
|
|
|
30
|
|
|
/** @var int */ |
|
31
|
|
|
protected $_scale; |
|
32
|
|
|
|
|
33
|
|
|
/** @var bool */ |
|
34
|
|
|
protected $_unsigned = false; |
|
35
|
|
|
|
|
36
|
|
|
/** @var bool */ |
|
37
|
|
|
protected $_fixed = false; |
|
38
|
|
|
|
|
39
|
|
|
/** @var bool */ |
|
40
|
|
|
protected $_notnull = true; |
|
41
|
|
|
|
|
42
|
|
|
/** @var mixed */ |
|
43
|
|
|
protected $_default; |
|
44
|
|
|
|
|
45
|
|
|
/** @var bool */ |
|
46
|
|
|
protected $_autoincrement = false; |
|
47
|
|
|
|
|
48
|
|
|
/** @var mixed[] */ |
|
49
|
|
|
protected $_platformOptions = []; |
|
50
|
|
|
|
|
51
|
|
|
/** @var string|null */ |
|
52
|
|
|
protected $_columnDefinition; |
|
53
|
|
|
|
|
54
|
|
|
/** @var string|null */ |
|
55
|
|
|
protected $_comment; |
|
56
|
|
|
|
|
57
|
|
|
/** @var mixed[] */ |
|
58
|
|
|
protected $_customSchemaOptions = []; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Creates a new Column. |
|
62
|
|
|
* |
|
63
|
17350 |
|
* @param mixed[] $options |
|
64
|
|
|
*/ |
|
65
|
17350 |
|
public function __construct(string $columnName, Type $type, array $options = []) |
|
66
|
17350 |
|
{ |
|
67
|
17350 |
|
$this->_setName($columnName); |
|
68
|
17350 |
|
$this->setType($type); |
|
69
|
|
|
$this->setOptions($options); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function getName() : string |
|
73
|
|
|
{ |
|
74
|
|
|
$name = parent::getName(); |
|
75
|
17350 |
|
assert(is_string($name)); |
|
76
|
|
|
|
|
77
|
17350 |
|
return $name; |
|
78
|
16889 |
|
} |
|
79
|
16889 |
|
|
|
80
|
|
|
/** |
|
81
|
2930 |
|
* @param mixed[] $options |
|
82
|
|
|
*/ |
|
83
|
2 |
|
public function setOptions(array $options) : self |
|
84
|
2930 |
|
{ |
|
85
|
2930 |
|
foreach ($options as $name => $value) { |
|
86
|
|
|
$method = 'set' . $name; |
|
87
|
2930 |
|
if (! method_exists($this, $method)) { |
|
88
|
|
|
// next major: throw an exception |
|
89
|
16888 |
|
@trigger_error(sprintf( |
|
90
|
|
|
'The "%s" column option is not supported,' . |
|
91
|
|
|
' setting it is deprecated and will cause an error in Doctrine 3.0', |
|
92
|
17350 |
|
$name |
|
93
|
|
|
), E_USER_DEPRECATED); |
|
94
|
|
|
|
|
95
|
|
|
continue; |
|
96
|
|
|
} |
|
97
|
|
|
$this->$method($value); |
|
98
|
17350 |
|
} |
|
99
|
|
|
|
|
100
|
17350 |
|
return $this; |
|
101
|
|
|
} |
|
102
|
17350 |
|
|
|
103
|
|
|
public function setType(Type $type) : self |
|
104
|
|
|
{ |
|
105
|
|
|
$this->_type = $type; |
|
106
|
|
|
|
|
107
|
|
|
return $this; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
16128 |
|
public function setLength(?int $length) : self |
|
111
|
|
|
{ |
|
112
|
16128 |
|
$this->_length = $length; |
|
113
|
16103 |
|
|
|
114
|
|
|
return $this; |
|
115
|
15887 |
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function setPrecision(?int $precision) : self |
|
118
|
16128 |
|
{ |
|
119
|
|
|
$this->_precision = $precision; |
|
120
|
|
|
|
|
121
|
|
|
return $this; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function setScale(?int $scale) : self |
|
125
|
|
|
{ |
|
126
|
15909 |
|
$this->_scale = $scale; |
|
127
|
|
|
|
|
128
|
15909 |
|
return $this; |
|
129
|
14773 |
|
} |
|
130
|
|
|
|
|
131
|
|
|
public function setUnsigned(bool $unsigned) : self |
|
132
|
15909 |
|
{ |
|
133
|
|
|
$this->_unsigned = $unsigned; |
|
134
|
15909 |
|
|
|
135
|
|
|
return $this; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function setFixed(bool $fixed) : self |
|
139
|
|
|
{ |
|
140
|
|
|
$this->_fixed = $fixed; |
|
141
|
|
|
|
|
142
|
15908 |
|
return $this; |
|
143
|
|
|
} |
|
144
|
15908 |
|
|
|
145
|
14706 |
|
public function setNotnull(bool $notnull) : self |
|
146
|
|
|
{ |
|
147
|
|
|
$this->_notnull = $notnull; |
|
148
|
15908 |
|
|
|
149
|
|
|
return $this; |
|
150
|
15908 |
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @param mixed $default |
|
154
|
|
|
*/ |
|
155
|
|
|
public function setDefault($default) : self |
|
156
|
|
|
{ |
|
157
|
|
|
$this->_default = $default; |
|
158
|
15890 |
|
|
|
159
|
|
|
return $this; |
|
160
|
15890 |
|
} |
|
161
|
|
|
|
|
162
|
15890 |
|
/** |
|
163
|
|
|
* @param mixed[] $platformOptions |
|
164
|
|
|
*/ |
|
165
|
|
|
public function setPlatformOptions(array $platformOptions) : self |
|
166
|
|
|
{ |
|
167
|
|
|
$this->_platformOptions = $platformOptions; |
|
168
|
|
|
|
|
169
|
|
|
return $this; |
|
170
|
16075 |
|
} |
|
171
|
|
|
|
|
172
|
16075 |
|
/** |
|
173
|
|
|
* @param mixed $value |
|
174
|
16075 |
|
*/ |
|
175
|
|
|
public function setPlatformOption(string $name, $value) : self |
|
176
|
|
|
{ |
|
177
|
|
|
$this->_platformOptions[$name] = $value; |
|
178
|
|
|
|
|
179
|
|
|
return $this; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
17084 |
|
public function setColumnDefinition(string $value) : self |
|
183
|
|
|
{ |
|
184
|
17084 |
|
$this->_columnDefinition = $value; |
|
185
|
|
|
|
|
186
|
17084 |
|
return $this; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
public function getType() : Type |
|
190
|
|
|
{ |
|
191
|
|
|
return $this->_type; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
15925 |
|
public function getLength() : ?int |
|
195
|
|
|
{ |
|
196
|
15925 |
|
return $this->_length; |
|
197
|
|
|
} |
|
198
|
15925 |
|
|
|
199
|
|
|
public function getPrecision() : ?int |
|
200
|
|
|
{ |
|
201
|
|
|
return $this->_precision; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
public function getScale() : ?int |
|
205
|
|
|
{ |
|
206
|
12822 |
|
return $this->_scale; |
|
207
|
|
|
} |
|
208
|
12822 |
|
|
|
209
|
|
|
public function getUnsigned() : bool |
|
210
|
12822 |
|
{ |
|
211
|
|
|
return $this->_unsigned; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
public function getFixed() : bool |
|
215
|
|
|
{ |
|
216
|
|
|
return $this->_fixed; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
15649 |
|
public function getNotnull() : bool |
|
220
|
|
|
{ |
|
221
|
15649 |
|
return $this->_notnull; |
|
222
|
|
|
} |
|
223
|
15649 |
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* @return mixed |
|
226
|
|
|
*/ |
|
227
|
|
|
public function getDefault() |
|
228
|
|
|
{ |
|
229
|
|
|
return $this->_default; |
|
230
|
|
|
} |
|
231
|
9055 |
|
|
|
232
|
|
|
/** |
|
233
|
9055 |
|
* @return mixed[] |
|
234
|
|
|
*/ |
|
235
|
9055 |
|
public function getPlatformOptions() : array |
|
236
|
|
|
{ |
|
237
|
|
|
return $this->_platformOptions; |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
public function hasPlatformOption(string $name) : bool |
|
241
|
17142 |
|
{ |
|
242
|
|
|
return isset($this->_platformOptions[$name]); |
|
243
|
17142 |
|
} |
|
244
|
|
|
|
|
245
|
|
|
/** |
|
246
|
|
|
* @return mixed |
|
247
|
|
|
*/ |
|
248
|
|
|
public function getPlatformOption(string $name) |
|
249
|
15093 |
|
{ |
|
250
|
|
|
return $this->_platformOptions[$name]; |
|
251
|
15093 |
|
} |
|
252
|
|
|
|
|
253
|
|
|
public function getColumnDefinition() : ?string |
|
254
|
|
|
{ |
|
255
|
|
|
return $this->_columnDefinition; |
|
256
|
|
|
} |
|
257
|
15083 |
|
|
|
258
|
|
|
public function getAutoincrement() : bool |
|
259
|
15083 |
|
{ |
|
260
|
|
|
return $this->_autoincrement; |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
public function setAutoincrement(bool $flag) : self |
|
264
|
|
|
{ |
|
265
|
15083 |
|
$this->_autoincrement = $flag; |
|
266
|
|
|
|
|
267
|
15083 |
|
return $this; |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
public function setComment(?string $comment) : self |
|
271
|
|
|
{ |
|
272
|
|
|
$this->_comment = $comment; |
|
273
|
15213 |
|
|
|
274
|
|
|
return $this; |
|
275
|
15213 |
|
} |
|
276
|
|
|
|
|
277
|
|
|
public function getComment() : ?string |
|
278
|
|
|
{ |
|
279
|
|
|
return $this->_comment; |
|
280
|
|
|
} |
|
281
|
15177 |
|
|
|
282
|
|
|
/** |
|
283
|
15177 |
|
* @param mixed $value |
|
284
|
|
|
*/ |
|
285
|
|
|
public function setCustomSchemaOption(string $name, $value) : self |
|
286
|
|
|
{ |
|
287
|
|
|
$this->_customSchemaOptions[$name] = $value; |
|
288
|
|
|
|
|
289
|
15252 |
|
return $this; |
|
290
|
|
|
} |
|
291
|
15252 |
|
|
|
292
|
|
|
public function hasCustomSchemaOption(string $name) : bool |
|
293
|
|
|
{ |
|
294
|
|
|
return isset($this->_customSchemaOptions[$name]); |
|
295
|
|
|
} |
|
296
|
|
|
|
|
297
|
15405 |
|
/** |
|
298
|
|
|
* @return mixed |
|
299
|
15405 |
|
*/ |
|
300
|
|
|
public function getCustomSchemaOption(string $name) |
|
301
|
|
|
{ |
|
302
|
|
|
return $this->_customSchemaOptions[$name]; |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
15980 |
|
/** |
|
306
|
|
|
* @param mixed[] $customSchemaOptions |
|
307
|
15980 |
|
*/ |
|
308
|
|
|
public function setCustomSchemaOptions(array $customSchemaOptions) : self |
|
309
|
|
|
{ |
|
310
|
|
|
$this->_customSchemaOptions = $customSchemaOptions; |
|
311
|
|
|
|
|
312
|
|
|
return $this; |
|
313
|
|
|
} |
|
314
|
|
|
|
|
315
|
17025 |
|
/** |
|
316
|
|
|
* @return mixed[] |
|
317
|
17025 |
|
*/ |
|
318
|
|
|
public function getCustomSchemaOptions() : array |
|
319
|
|
|
{ |
|
320
|
|
|
return $this->_customSchemaOptions; |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
/** |
|
324
|
|
|
* @return mixed[] |
|
325
|
14364 |
|
*/ |
|
326
|
|
|
public function toArray() : array |
|
327
|
14364 |
|
{ |
|
328
|
|
|
return array_merge([ |
|
329
|
|
|
'name' => $this->_name, |
|
330
|
|
|
'type' => $this->_type, |
|
331
|
|
|
'default' => $this->_default, |
|
332
|
|
|
'notnull' => $this->_notnull, |
|
333
|
|
|
'length' => $this->_length, |
|
334
|
|
|
'precision' => $this->_precision, |
|
335
|
|
|
'scale' => $this->_scale, |
|
336
|
|
|
'fixed' => $this->_fixed, |
|
337
|
|
|
'unsigned' => $this->_unsigned, |
|
338
|
|
|
'autoincrement' => $this->_autoincrement, |
|
339
|
|
|
'columnDefinition' => $this->_columnDefinition, |
|
340
|
|
|
'comment' => $this->_comment, |
|
341
|
15790 |
|
], $this->_platformOptions, $this->_customSchemaOptions); |
|
342
|
|
|
} |
|
343
|
|
|
} |
|
344
|
|
|
|