-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathAbstractColumnSchema.php
226 lines (190 loc) · 4.78 KB
/
AbstractColumnSchema.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<?php
declare(strict_types=1);
namespace Yiisoft\Db\Schema\Column;
use Yiisoft\Db\Constant\PhpType;
/**
* Represents the metadata of a column in a database table.
*
* It provides information about the column's name, type, size, precision, and other details.
*
* The `ColumnSchema` class is used to store and retrieve metadata about a column in a database table.
*
* It's typically used in conjunction with the TableSchema class, which represents the metadata of a database table as a
* whole.
*
* Here is an example of how to use the `ColumnSchema` class:
*
* ```php
* use Yiisoft\Db\Schema\ColumnSchema;
*
* $column = (new ColumnSchema())
* ->name('id')
* ->allowNull(false)
* ->dbType('int(11)')
* ->phpType('integer')
* ->type('integer')
* ->defaultValue(0)
* ->autoIncrement()
* ->primaryKey();
* ```
*/
abstract class AbstractColumnSchema implements ColumnSchemaInterface
{
private bool $allowNull = false;
private bool $autoIncrement = false;
private string|null $comment = null;
private bool $computed = false;
private string|null $dbType = null;
private mixed $defaultValue = null;
private array|null $enumValues = null;
private string|null $extra = null;
private bool $isPrimaryKey = false;
private string|null $name = null;
private int|null $precision = null;
private int|null $scale = null;
private int|null $size = null;
private bool $unsigned = false;
public function __construct(
private string $type,
) {
}
public function allowNull(bool $allowNull = true): static
{
$this->allowNull = $allowNull;
return $this;
}
public function autoIncrement(bool $autoIncrement = true): static
{
$this->autoIncrement = $autoIncrement;
return $this;
}
public function comment(string|null $comment): static
{
$this->comment = $comment;
return $this;
}
public function computed(bool $computed = true): static
{
$this->computed = $computed;
return $this;
}
public function dbType(string|null $dbType): static
{
$this->dbType = $dbType;
return $this;
}
public function defaultValue(mixed $defaultValue): static
{
$this->defaultValue = $defaultValue;
return $this;
}
public function enumValues(array|null $enumValues): static
{
$this->enumValues = $enumValues;
return $this;
}
public function extra(string|null $extra): static
{
$this->extra = $extra;
return $this;
}
public function getComment(): string|null
{
return $this->comment;
}
public function getDbType(): string|null
{
return $this->dbType;
}
public function getDefaultValue(): mixed
{
return $this->defaultValue;
}
public function getEnumValues(): array|null
{
return $this->enumValues;
}
public function getExtra(): string|null
{
return $this->extra;
}
public function getName(): string|null
{
return $this->name;
}
public function getPrecision(): int|null
{
return $this->precision;
}
public function getPhpType(): string
{
return PhpType::MIXED;
}
public function getScale(): int|null
{
return $this->scale;
}
public function getSize(): int|null
{
return $this->size;
}
public function getType(): string
{
return $this->type;
}
public function isAllowNull(): bool
{
return $this->allowNull;
}
public function isAutoIncrement(): bool
{
return $this->autoIncrement;
}
public function isComputed(): bool
{
return $this->computed;
}
public function isPrimaryKey(): bool
{
return $this->isPrimaryKey;
}
public function isUnsigned(): bool
{
return $this->unsigned;
}
public function name(string|null $name): static
{
$this->name = $name;
return $this;
}
public function precision(int|null $precision): static
{
$this->precision = $precision;
return $this;
}
public function primaryKey(bool $isPrimaryKey = true): static
{
$this->isPrimaryKey = $isPrimaryKey;
return $this;
}
public function scale(int|null $scale): static
{
$this->scale = $scale;
return $this;
}
public function size(int|null $size): static
{
$this->size = $size;
return $this;
}
public function type(string $type): static
{
$this->type = $type;
return $this;
}
public function unsigned(bool $unsigned = true): static
{
$this->unsigned = $unsigned;
return $this;
}
}