1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* MIT License |
5
|
|
|
* For full license information, please view the LICENSE file that was distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Phinx\Db\Table; |
9
|
|
|
|
10
|
|
|
use Phinx\Db\Adapter\AdapterInterface; |
11
|
|
|
use RuntimeException; |
12
|
|
|
use UnexpectedValueException; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* This object is based loosely on: http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/Table.html. |
16
|
|
|
*/ |
17
|
|
|
class Column |
18
|
|
|
{ |
19
|
|
|
public const BIGINTEGER = AdapterInterface::PHINX_TYPE_BIG_INTEGER; |
20
|
|
|
public const SMALLINTEGER = AdapterInterface::PHINX_TYPE_SMALL_INTEGER; |
21
|
|
|
public const TINYINTEGER = AdapterInterface::PHINX_TYPE_TINY_INTEGER; |
22
|
|
|
public const BINARY = AdapterInterface::PHINX_TYPE_BINARY; |
23
|
|
|
public const BOOLEAN = AdapterInterface::PHINX_TYPE_BOOLEAN; |
24
|
|
|
public const CHAR = AdapterInterface::PHINX_TYPE_CHAR; |
25
|
|
|
public const DATE = AdapterInterface::PHINX_TYPE_DATE; |
26
|
|
|
public const DATETIME = AdapterInterface::PHINX_TYPE_DATETIME; |
27
|
|
|
public const DECIMAL = AdapterInterface::PHINX_TYPE_DECIMAL; |
28
|
|
|
public const FLOAT = AdapterInterface::PHINX_TYPE_FLOAT; |
29
|
|
|
public const INTEGER = AdapterInterface::PHINX_TYPE_INTEGER; |
30
|
|
|
public const STRING = AdapterInterface::PHINX_TYPE_STRING; |
31
|
|
|
public const TEXT = AdapterInterface::PHINX_TYPE_TEXT; |
32
|
|
|
public const TIME = AdapterInterface::PHINX_TYPE_TIME; |
33
|
|
|
public const TIMESTAMP = AdapterInterface::PHINX_TYPE_TIMESTAMP; |
34
|
|
|
public const UUID = AdapterInterface::PHINX_TYPE_UUID; |
35
|
|
|
public const BINARYUUID = AdapterInterface::PHINX_TYPE_BINARYUUID; |
36
|
|
|
/** MySQL-only column type */ |
37
|
|
|
public const ENUM = AdapterInterface::PHINX_TYPE_ENUM; |
38
|
|
|
/** MySQL-only column type */ |
39
|
|
|
public const SET = AdapterInterface::PHINX_TYPE_STRING; |
40
|
|
|
/** MySQL-only column type */ |
41
|
|
|
public const BLOB = AdapterInterface::PHINX_TYPE_BLOB; |
42
|
|
|
/** MySQL-only column type */ |
43
|
|
|
public const YEAR = AdapterInterface::PHINX_TYPE_YEAR; |
44
|
|
|
/** MySQL/Postgres-only column type */ |
45
|
|
|
public const JSON = AdapterInterface::PHINX_TYPE_JSON; |
46
|
|
|
/** Postgres-only column type */ |
47
|
|
|
public const JSONB = AdapterInterface::PHINX_TYPE_JSONB; |
48
|
|
|
/** Postgres-only column type */ |
49
|
|
|
public const CIDR = AdapterInterface::PHINX_TYPE_CIDR; |
50
|
|
|
/** Postgres-only column type */ |
51
|
|
|
public const INET = AdapterInterface::PHINX_TYPE_INET; |
52
|
|
|
/** Postgres-only column type */ |
53
|
|
|
public const MACADDR = AdapterInterface::PHINX_TYPE_MACADDR; |
54
|
|
|
/** Postgres-only column type */ |
55
|
|
|
public const INTERVAL = AdapterInterface::PHINX_TYPE_INTERVAL; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var string |
59
|
|
|
*/ |
60
|
|
|
protected $name; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var string|\Phinx\Util\Literal |
64
|
|
|
*/ |
65
|
|
|
protected $type; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var int |
69
|
|
|
*/ |
70
|
|
|
protected $limit; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var bool |
74
|
|
|
*/ |
75
|
|
|
protected $null = true; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @var mixed|null |
79
|
|
|
*/ |
80
|
|
|
protected $default; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @var bool |
84
|
|
|
*/ |
85
|
|
|
protected $identity = false; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @var int |
89
|
|
|
*/ |
90
|
|
|
protected $seed; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @var int |
94
|
|
|
*/ |
95
|
|
|
protected $increment; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @var int |
99
|
|
|
*/ |
100
|
|
|
protected $scale; |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @var string |
104
|
|
|
*/ |
105
|
|
|
protected $after; |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @var string |
109
|
|
|
*/ |
110
|
|
|
protected $update; |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @var string |
114
|
|
|
*/ |
115
|
|
|
protected $comment; |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @var bool |
119
|
|
|
*/ |
120
|
|
|
protected $signed = true; |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @var bool |
124
|
|
|
*/ |
125
|
|
|
protected $timezone = false; |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @var array |
129
|
|
|
*/ |
130
|
215 |
|
protected $properties = []; |
131
|
|
|
|
132
|
215 |
|
/** |
133
|
215 |
|
* @var string |
134
|
|
|
*/ |
135
|
|
|
protected $collation; |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @var string |
139
|
|
|
*/ |
140
|
|
|
protected $encoding; |
141
|
212 |
|
|
142
|
|
|
/** |
143
|
212 |
|
* @var int|null |
144
|
|
|
*/ |
145
|
|
|
protected $srid; |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @var array |
149
|
|
|
*/ |
150
|
|
|
protected $values; |
151
|
|
|
|
152
|
214 |
|
/** |
153
|
|
|
* Sets the column name. |
154
|
214 |
|
* |
155
|
214 |
|
* @param string $name Name |
156
|
|
|
* |
157
|
|
|
* @return $this |
158
|
|
|
*/ |
159
|
|
|
public function setName($name) |
160
|
|
|
{ |
161
|
|
|
$this->name = $name; |
162
|
|
|
|
163
|
212 |
|
return $this; |
164
|
|
|
} |
165
|
212 |
|
|
166
|
|
|
/** |
167
|
|
|
* Gets the column name. |
168
|
|
|
* |
169
|
|
|
* @return string|null |
170
|
|
|
*/ |
171
|
|
|
public function getName() |
172
|
|
|
{ |
173
|
|
|
return $this->name; |
174
|
192 |
|
} |
175
|
|
|
|
176
|
192 |
|
/** |
177
|
192 |
|
* Sets the column type. |
178
|
|
|
* |
179
|
|
|
* @param string|\Phinx\Util\Literal $type Column type |
180
|
|
|
* |
181
|
|
|
* @return $this |
182
|
|
|
*/ |
183
|
|
|
public function setType($type) |
184
|
|
|
{ |
185
|
192 |
|
$this->type = $type; |
186
|
|
|
|
187
|
192 |
|
return $this; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Gets the column type. |
192
|
|
|
* |
193
|
|
|
* @return string|\Phinx\Util\Literal |
194
|
|
|
*/ |
195
|
|
|
public function getType() |
196
|
208 |
|
{ |
197
|
|
|
return $this->type; |
198
|
208 |
|
} |
199
|
208 |
|
|
200
|
|
|
/** |
201
|
|
|
* Sets the column limit. |
202
|
|
|
* |
203
|
|
|
* @param int $limit Limit |
204
|
|
|
* |
205
|
|
|
* @return $this |
206
|
|
|
*/ |
207
|
215 |
|
public function setLimit($limit) |
208
|
|
|
{ |
209
|
215 |
|
$this->limit = $limit; |
210
|
|
|
|
211
|
|
|
return $this; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Gets the column limit. |
216
|
|
|
* |
217
|
214 |
|
* @return int |
218
|
|
|
*/ |
219
|
214 |
|
public function getLimit() |
220
|
|
|
{ |
221
|
|
|
return $this->limit; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* Sets whether the column allows nulls. |
226
|
|
|
* |
227
|
|
|
* @param bool $null Null |
228
|
207 |
|
* |
229
|
|
|
* @return $this |
230
|
207 |
|
*/ |
231
|
207 |
|
public function setNull($null) |
232
|
|
|
{ |
233
|
|
|
$this->null = (bool)$null; |
234
|
|
|
|
235
|
|
|
return $this; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
215 |
|
* Gets whether the column allows nulls. |
240
|
|
|
* |
241
|
215 |
|
* @return bool |
242
|
|
|
*/ |
243
|
|
|
public function getNull() |
244
|
|
|
{ |
245
|
|
|
return $this->null; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Does the column allow nulls? |
250
|
158 |
|
* |
251
|
|
|
* @return bool |
252
|
158 |
|
*/ |
253
|
158 |
|
public function isNull() |
254
|
|
|
{ |
255
|
|
|
return $this->getNull(); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* Sets the default column value. |
260
|
|
|
* |
261
|
199 |
|
* @param mixed $default Default |
262
|
|
|
* |
263
|
199 |
|
* @return $this |
264
|
|
|
*/ |
265
|
|
|
public function setDefault($default) |
266
|
|
|
{ |
267
|
|
|
$this->default = $default; |
268
|
|
|
|
269
|
|
|
return $this; |
270
|
|
|
} |
271
|
198 |
|
|
272
|
|
|
/** |
273
|
198 |
|
* Gets the default column value. |
274
|
|
|
* |
275
|
|
|
* @return mixed |
276
|
|
|
*/ |
277
|
|
|
public function getDefault() |
278
|
|
|
{ |
279
|
|
|
return $this->default; |
280
|
|
|
} |
281
|
|
|
|
282
|
1 |
|
/** |
283
|
|
|
* Sets whether or not the column is an identity column. |
284
|
1 |
|
* |
285
|
1 |
|
* @param bool $identity Identity |
286
|
|
|
* |
287
|
|
|
* @return $this |
288
|
|
|
*/ |
289
|
|
|
public function setIdentity($identity) |
290
|
|
|
{ |
291
|
|
|
$this->identity = $identity; |
292
|
|
|
|
293
|
20 |
|
return $this; |
294
|
|
|
} |
295
|
20 |
|
|
296
|
|
|
/** |
297
|
|
|
* Gets whether or not the column is an identity column. |
298
|
|
|
* |
299
|
|
|
* @return bool |
300
|
|
|
*/ |
301
|
|
|
public function getIdentity() |
302
|
|
|
{ |
303
|
|
|
return $this->identity; |
304
|
15 |
|
} |
305
|
|
|
|
306
|
15 |
|
/** |
307
|
15 |
|
* Is the column an identity column? |
308
|
|
|
* |
309
|
|
|
* @return bool |
310
|
|
|
*/ |
311
|
|
|
public function isIdentity() |
312
|
|
|
{ |
313
|
|
|
return $this->getIdentity(); |
314
|
|
|
} |
315
|
145 |
|
|
316
|
|
|
/** |
317
|
145 |
|
* Sets the name of the column to add this column after. |
318
|
|
|
* |
319
|
|
|
* @param string $after After |
320
|
|
|
* |
321
|
|
|
* @return $this |
322
|
|
|
*/ |
323
|
|
|
public function setAfter($after) |
324
|
|
|
{ |
325
|
|
|
$this->after = $after; |
326
|
9 |
|
|
327
|
|
|
return $this; |
328
|
9 |
|
} |
329
|
9 |
|
|
330
|
|
|
/** |
331
|
|
|
* Returns the name of the column to add this column after. |
332
|
|
|
* |
333
|
|
|
* @return string |
334
|
|
|
*/ |
335
|
|
|
public function getAfter() |
336
|
|
|
{ |
337
|
131 |
|
return $this->after; |
338
|
|
|
} |
339
|
131 |
|
|
340
|
|
|
/** |
341
|
|
|
* Sets the 'ON UPDATE' mysql column function. |
342
|
|
|
* |
343
|
|
|
* @param string $update On Update function |
344
|
|
|
* |
345
|
|
|
* @return $this |
346
|
|
|
*/ |
347
|
|
|
public function setUpdate($update) |
348
|
9 |
|
{ |
349
|
|
|
$this->update = $update; |
350
|
9 |
|
|
351
|
9 |
|
return $this; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* Returns the value of the ON UPDATE column function. |
356
|
|
|
* |
357
|
|
|
* @return string |
358
|
|
|
*/ |
359
|
2 |
|
public function getUpdate() |
360
|
|
|
{ |
361
|
2 |
|
return $this->update; |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
/** |
365
|
|
|
* Sets the number precision for decimal or float column. |
366
|
|
|
* |
367
|
|
|
* For example `DECIMAL(5,2)`, 5 is the precision and 2 is the scale, |
368
|
|
|
* and the column could store value from -999.99 to 999.99. |
369
|
|
|
* |
370
|
9 |
|
* @param int $precision Number precision |
371
|
|
|
* |
372
|
9 |
|
* @return $this |
373
|
9 |
|
*/ |
374
|
|
|
public function setPrecision($precision) |
375
|
|
|
{ |
376
|
|
|
$this->setLimit($precision); |
377
|
|
|
|
378
|
|
|
return $this; |
379
|
|
|
} |
380
|
|
|
|
381
|
198 |
|
/** |
382
|
|
|
* Gets the number precision for decimal or float column. |
383
|
198 |
|
* |
384
|
|
|
* For example `DECIMAL(5,2)`, 5 is the precision and 2 is the scale, |
385
|
|
|
* and the column could store value from -999.99 to 999.99. |
386
|
|
|
* |
387
|
|
|
* @return int |
388
|
|
|
*/ |
389
|
|
|
public function getPrecision() |
390
|
|
|
{ |
391
|
|
|
return $this->limit; |
392
|
68 |
|
} |
393
|
|
|
|
394
|
68 |
|
/** |
395
|
68 |
|
* Gets the column identity seed. |
396
|
|
|
* |
397
|
|
|
* @return int |
398
|
|
|
*/ |
399
|
|
|
public function getSeed() |
400
|
|
|
{ |
401
|
|
|
return $this->seed; |
402
|
|
|
} |
403
|
89 |
|
|
404
|
|
|
/** |
405
|
89 |
|
* Gets the column identity increment. |
406
|
|
|
* |
407
|
|
|
* @return int |
408
|
|
|
*/ |
409
|
|
|
public function getIncrement() |
410
|
|
|
{ |
411
|
|
|
return $this->increment; |
412
|
|
|
} |
413
|
89 |
|
|
414
|
|
|
/** |
415
|
89 |
|
* Sets the column identity seed. |
416
|
|
|
* |
417
|
|
|
* @param int $seed Number seed |
418
|
|
|
* |
419
|
|
|
* @return $this |
420
|
|
|
*/ |
421
|
|
|
public function setSeed($seed) |
422
|
|
|
{ |
423
|
|
|
$this->seed = $seed; |
424
|
|
|
|
425
|
1 |
|
return $this; |
426
|
|
|
} |
427
|
1 |
|
|
428
|
1 |
|
/** |
429
|
|
|
* Sets the column identity increment. |
430
|
|
|
* |
431
|
|
|
* @param int $increment Number increment |
432
|
|
|
* |
433
|
|
|
* @return $this |
434
|
|
|
*/ |
435
|
|
|
public function setIncrement($increment) |
436
|
68 |
|
{ |
437
|
|
|
$this->increment = $increment; |
438
|
68 |
|
|
439
|
|
|
return $this; |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
/** |
443
|
|
|
* Sets the number scale for decimal or float column. |
444
|
|
|
* |
445
|
|
|
* For example `DECIMAL(5,2)`, 5 is the precision and 2 is the scale, |
446
|
68 |
|
* and the column could store value from -999.99 to 999.99. |
447
|
|
|
* |
448
|
68 |
|
* @param int $scale Number scale |
449
|
|
|
* |
450
|
|
|
* @return $this |
451
|
|
|
*/ |
452
|
|
|
public function setScale($scale) |
453
|
|
|
{ |
454
|
|
|
$this->scale = $scale; |
455
|
|
|
|
456
|
|
|
return $this; |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
/** |
460
|
|
|
* Gets the number scale for decimal or float column. |
461
|
|
|
* |
462
|
|
|
* For example `DECIMAL(5,2)`, 5 is the precision and 2 is the scale, |
463
|
|
|
* and the column could store value from -999.99 to 999.99. |
464
|
|
|
* |
465
|
|
|
* @return int |
466
|
|
|
*/ |
467
|
|
|
public function getScale() |
468
|
|
|
{ |
469
|
|
|
return $this->scale; |
470
|
|
|
} |
471
|
|
|
|
472
|
|
|
/** |
473
|
|
|
* Sets the number precision and scale for decimal or float column. |
474
|
|
|
* |
475
|
|
|
* For example `DECIMAL(5,2)`, 5 is the precision and 2 is the scale, |
476
|
|
|
* and the column could store value from -999.99 to 999.99. |
477
|
|
|
* |
478
|
|
|
* @param int $precision Number precision |
479
|
|
|
* @param int $scale Number scale |
480
|
|
|
* |
481
|
9 |
|
* @return $this |
482
|
|
|
*/ |
483
|
9 |
|
public function setPrecisionAndScale($precision, $scale) |
484
|
2 |
|
{ |
485
|
2 |
|
$this->setLimit($precision); |
486
|
9 |
|
$this->scale = $scale; |
487
|
9 |
|
|
488
|
|
|
return $this; |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
/** |
492
|
|
|
* Sets the column comment. |
493
|
|
|
* |
494
|
|
|
* @param string $comment Comment |
495
|
131 |
|
* |
496
|
|
|
* @return $this |
497
|
131 |
|
*/ |
498
|
|
|
public function setComment($comment) |
499
|
|
|
{ |
500
|
|
|
$this->comment = $comment; |
501
|
|
|
|
502
|
|
|
return $this; |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
/** |
506
|
|
|
* Gets the column comment. |
507
|
|
|
* |
508
|
1 |
|
* @return string |
509
|
|
|
*/ |
510
|
|
|
public function getComment() |
511
|
1 |
|
{ |
512
|
1 |
|
return $this->comment; |
513
|
1 |
|
} |
514
|
1 |
|
|
515
|
1 |
|
/** |
516
|
|
|
* Sets whether field should be signed. |
517
|
|
|
* |
518
|
|
|
* @param bool $signed Signed |
519
|
1 |
|
* |
520
|
|
|
* @return $this |
521
|
1 |
|
*/ |
522
|
|
|
public function setSigned($signed) |
523
|
|
|
{ |
524
|
|
|
$this->signed = (bool)$signed; |
525
|
|
|
|
526
|
|
|
return $this; |
527
|
|
|
} |
528
|
|
|
|
529
|
89 |
|
/** |
530
|
|
|
* Gets whether field should be signed. |
531
|
89 |
|
* |
532
|
|
|
* @return bool |
533
|
|
|
*/ |
534
|
|
|
public function getSigned() |
535
|
|
|
{ |
536
|
|
|
return $this->signed; |
537
|
|
|
} |
538
|
|
|
|
539
|
|
|
/** |
540
|
|
|
* Should the column be signed? |
541
|
|
|
* |
542
|
|
|
* @return bool |
543
|
|
|
*/ |
544
|
|
|
public function isSigned() |
545
|
|
|
{ |
546
|
|
|
return $this->getSigned(); |
547
|
|
|
} |
548
|
|
|
|
549
|
|
|
/** |
550
|
|
|
* Sets whether the field should have a timezone identifier. |
551
|
|
|
* Used for date/time columns only! |
552
|
|
|
* |
553
|
|
|
* @param bool $timezone Timezone |
554
|
|
|
* |
555
|
|
|
* @return $this |
556
|
|
|
*/ |
557
|
|
|
public function setTimezone($timezone) |
558
|
|
|
{ |
559
|
|
|
$this->timezone = (bool)$timezone; |
560
|
|
|
|
561
|
|
|
return $this; |
562
|
|
|
} |
563
|
89 |
|
|
564
|
|
|
/** |
565
|
89 |
|
* Gets whether field has a timezone identifier. |
566
|
|
|
* |
567
|
|
|
* @return bool |
568
|
|
|
*/ |
569
|
|
|
public function getTimezone() |
570
|
|
|
{ |
571
|
|
|
return $this->timezone; |
572
|
|
|
} |
573
|
209 |
|
|
574
|
|
|
/** |
575
|
|
|
* Should the column have a timezone? |
576
|
209 |
|
* |
577
|
209 |
|
* @return bool |
578
|
209 |
|
*/ |
579
|
209 |
|
public function isTimezone() |
580
|
209 |
|
{ |
581
|
209 |
|
return $this->getTimezone(); |
582
|
209 |
|
} |
583
|
209 |
|
|
584
|
209 |
|
/** |
585
|
209 |
|
* Sets field properties. |
586
|
209 |
|
* |
587
|
209 |
|
* @param array $properties Properties |
588
|
209 |
|
* |
589
|
209 |
|
* @return $this |
590
|
209 |
|
*/ |
591
|
209 |
|
public function setProperties($properties) |
592
|
|
|
{ |
593
|
|
|
$this->properties = $properties; |
594
|
|
|
|
595
|
|
|
return $this; |
596
|
|
|
} |
597
|
|
|
|
598
|
|
|
/** |
599
|
209 |
|
* Gets field properties |
600
|
|
|
* |
601
|
|
|
* @return array |
602
|
209 |
|
*/ |
603
|
209 |
|
public function getProperties() |
604
|
|
|
{ |
605
|
|
|
return $this->properties; |
606
|
|
|
} |
607
|
|
|
|
608
|
|
|
/** |
609
|
|
|
* Sets field values. |
610
|
|
|
* |
611
|
|
|
* @param string[]|string $values Value(s) |
612
|
209 |
|
* |
613
|
|
|
* @return $this |
614
|
209 |
|
*/ |
615
|
209 |
|
public function setValues($values) |
616
|
|
|
{ |
617
|
209 |
|
if (!is_array($values)) { |
618
|
208 |
|
$values = preg_split('/,\s*/', $values); |
619
|
|
|
} |
620
|
|
|
$this->values = $values; |
|
|
|
|
621
|
|
|
|
622
|
|
|
return $this; |
623
|
208 |
|
} |
624
|
1 |
|
|
625
|
|
|
/** |
626
|
|
|
* Gets field values |
627
|
207 |
|
* |
628
|
207 |
|
* @return array |
629
|
208 |
|
*/ |
630
|
208 |
|
public function getValues() |
631
|
|
|
{ |
632
|
|
|
return $this->values; |
633
|
|
|
} |
634
|
|
|
|
635
|
|
|
/** |
636
|
|
|
* Sets the column collation. |
637
|
|
|
* |
638
|
|
|
* @param string $collation Collation |
639
|
|
|
* |
640
|
|
|
* @return $this |
641
|
|
|
*/ |
642
|
|
|
public function setCollation($collation) |
643
|
|
|
{ |
644
|
|
|
$this->collation = $collation; |
645
|
|
|
|
646
|
|
|
return $this; |
647
|
|
|
} |
648
|
|
|
|
649
|
|
|
/** |
650
|
|
|
* Gets the column collation. |
651
|
|
|
* |
652
|
|
|
* @return string |
653
|
|
|
*/ |
654
|
|
|
public function getCollation() |
655
|
|
|
{ |
656
|
|
|
return $this->collation; |
657
|
|
|
} |
658
|
|
|
|
659
|
|
|
/** |
660
|
|
|
* Sets the column character set. |
661
|
|
|
* |
662
|
|
|
* @param string $encoding Encoding |
663
|
|
|
* |
664
|
|
|
* @return $this |
665
|
|
|
*/ |
666
|
|
|
public function setEncoding($encoding) |
667
|
|
|
{ |
668
|
|
|
$this->encoding = $encoding; |
669
|
|
|
|
670
|
|
|
return $this; |
671
|
|
|
} |
672
|
|
|
|
673
|
|
|
/** |
674
|
|
|
* Gets the column character set. |
675
|
|
|
* |
676
|
|
|
* @return string |
677
|
|
|
*/ |
678
|
|
|
public function getEncoding() |
679
|
|
|
{ |
680
|
|
|
return $this->encoding; |
681
|
|
|
} |
682
|
|
|
|
683
|
|
|
/** |
684
|
|
|
* Sets the column SRID. |
685
|
|
|
* |
686
|
|
|
* @param int $srid SRID |
687
|
|
|
* @return \Phinx\Db\Table\Column |
688
|
|
|
*/ |
689
|
|
|
public function setSrid($srid) |
690
|
|
|
{ |
691
|
|
|
$this->srid = $srid; |
692
|
|
|
|
693
|
|
|
return $this; |
694
|
|
|
} |
695
|
|
|
|
696
|
|
|
/** |
697
|
|
|
* Gets the column SRID. |
698
|
|
|
* |
699
|
|
|
* @return int|null |
700
|
|
|
*/ |
701
|
|
|
public function getSrid() |
702
|
|
|
{ |
703
|
|
|
return $this->srid; |
704
|
|
|
} |
705
|
|
|
|
706
|
|
|
/** |
707
|
|
|
* Gets all allowed options. Each option must have a corresponding `setFoo` method. |
708
|
|
|
* |
709
|
|
|
* @return array |
710
|
|
|
*/ |
711
|
|
|
protected function getValidOptions() |
712
|
|
|
{ |
713
|
|
|
return [ |
714
|
|
|
'limit', |
715
|
|
|
'default', |
716
|
|
|
'null', |
717
|
|
|
'identity', |
718
|
|
|
'scale', |
719
|
|
|
'after', |
720
|
|
|
'update', |
721
|
|
|
'comment', |
722
|
|
|
'signed', |
723
|
|
|
'timezone', |
724
|
|
|
'properties', |
725
|
|
|
'values', |
726
|
|
|
'collation', |
727
|
|
|
'encoding', |
728
|
|
|
'srid', |
729
|
|
|
'seed', |
730
|
|
|
'increment', |
731
|
|
|
]; |
732
|
|
|
} |
733
|
|
|
|
734
|
|
|
/** |
735
|
|
|
* Gets all aliased options. Each alias must reference a valid option. |
736
|
|
|
* |
737
|
|
|
* @return array |
738
|
|
|
*/ |
739
|
|
|
protected function getAliasedOptions() |
740
|
|
|
{ |
741
|
|
|
return [ |
742
|
|
|
'length' => 'limit', |
743
|
|
|
'precision' => 'limit', |
744
|
|
|
]; |
745
|
|
|
} |
746
|
|
|
|
747
|
|
|
/** |
748
|
|
|
* Utility method that maps an array of column options to this objects methods. |
749
|
|
|
* |
750
|
|
|
* @param array $options Options |
751
|
|
|
* |
752
|
|
|
* @throws \RuntimeException |
753
|
|
|
* |
754
|
|
|
* @return $this |
755
|
|
|
*/ |
756
|
|
|
public function setOptions($options) |
757
|
|
|
{ |
758
|
|
|
$validOptions = $this->getValidOptions(); |
759
|
|
|
$aliasOptions = $this->getAliasedOptions(); |
760
|
|
|
|
761
|
|
|
if (isset($options['identity']) && $options['identity'] && !isset($options['null'])) { |
762
|
|
|
$options['null'] = false; |
763
|
|
|
} |
764
|
|
|
|
765
|
|
|
foreach ($options as $option => $value) { |
766
|
|
|
if (isset($aliasOptions[$option])) { |
767
|
|
|
// proxy alias -> option |
768
|
|
|
$option = $aliasOptions[$option]; |
769
|
|
|
} |
770
|
|
|
|
771
|
|
|
if (!in_array($option, $validOptions, true)) { |
772
|
|
|
throw new RuntimeException(sprintf('"%s" is not a valid column option.', $option)); |
773
|
|
|
} |
774
|
|
|
|
775
|
|
|
$method = 'set' . ucfirst($option); |
776
|
|
|
$this->$method($value); |
777
|
|
|
} |
778
|
|
|
|
779
|
|
|
return $this; |
780
|
|
|
} |
781
|
|
|
} |
782
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.