summaryrefslogtreecommitdiff
path: root/vendor/doctrine/dbal/src/Schema/Column.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/doctrine/dbal/src/Schema/Column.php')
-rw-r--r--vendor/doctrine/dbal/src/Schema/Column.php252
1 files changed, 252 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Schema/Column.php b/vendor/doctrine/dbal/src/Schema/Column.php
new file mode 100644
index 0000000..8963cd7
--- /dev/null
+++ b/vendor/doctrine/dbal/src/Schema/Column.php
@@ -0,0 +1,252 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\DBAL\Schema;
6
7use Doctrine\DBAL\Schema\Exception\UnknownColumnOption;
8use Doctrine\DBAL\Types\Type;
9
10use function array_merge;
11use function method_exists;
12
13/**
14 * Object representation of a database column.
15 */
16class Column extends AbstractAsset
17{
18 protected Type $_type;
19
20 protected ?int $_length = null;
21
22 protected ?int $_precision = null;
23
24 protected int $_scale = 0;
25
26 protected bool $_unsigned = false;
27
28 protected bool $_fixed = false;
29
30 protected bool $_notnull = true;
31
32 protected mixed $_default = null;
33
34 protected bool $_autoincrement = false;
35
36 /** @var array<string, mixed> */
37 protected array $_platformOptions = [];
38
39 protected ?string $_columnDefinition = null;
40
41 protected string $_comment = '';
42
43 /**
44 * Creates a new Column.
45 *
46 * @param array<string, mixed> $options
47 */
48 public function __construct(string $name, Type $type, array $options = [])
49 {
50 $this->_setName($name);
51 $this->setType($type);
52 $this->setOptions($options);
53 }
54
55 /** @param array<string, mixed> $options */
56 public function setOptions(array $options): self
57 {
58 foreach ($options as $name => $value) {
59 $method = 'set' . $name;
60
61 if (! method_exists($this, $method)) {
62 throw UnknownColumnOption::new($name);
63 }
64
65 $this->$method($value);
66 }
67
68 return $this;
69 }
70
71 public function setType(Type $type): self
72 {
73 $this->_type = $type;
74
75 return $this;
76 }
77
78 public function setLength(?int $length): self
79 {
80 $this->_length = $length;
81
82 return $this;
83 }
84
85 public function setPrecision(?int $precision): self
86 {
87 $this->_precision = $precision;
88
89 return $this;
90 }
91
92 public function setScale(int $scale): self
93 {
94 $this->_scale = $scale;
95
96 return $this;
97 }
98
99 public function setUnsigned(bool $unsigned): self
100 {
101 $this->_unsigned = $unsigned;
102
103 return $this;
104 }
105
106 public function setFixed(bool $fixed): self
107 {
108 $this->_fixed = $fixed;
109
110 return $this;
111 }
112
113 public function setNotnull(bool $notnull): self
114 {
115 $this->_notnull = $notnull;
116
117 return $this;
118 }
119
120 public function setDefault(mixed $default): self
121 {
122 $this->_default = $default;
123
124 return $this;
125 }
126
127 /** @param array<string, mixed> $platformOptions */
128 public function setPlatformOptions(array $platformOptions): self
129 {
130 $this->_platformOptions = $platformOptions;
131
132 return $this;
133 }
134
135 public function setPlatformOption(string $name, mixed $value): self
136 {
137 $this->_platformOptions[$name] = $value;
138
139 return $this;
140 }
141
142 public function setColumnDefinition(?string $value): self
143 {
144 $this->_columnDefinition = $value;
145
146 return $this;
147 }
148
149 public function getType(): Type
150 {
151 return $this->_type;
152 }
153
154 public function getLength(): ?int
155 {
156 return $this->_length;
157 }
158
159 public function getPrecision(): ?int
160 {
161 return $this->_precision;
162 }
163
164 public function getScale(): int
165 {
166 return $this->_scale;
167 }
168
169 public function getUnsigned(): bool
170 {
171 return $this->_unsigned;
172 }
173
174 public function getFixed(): bool
175 {
176 return $this->_fixed;
177 }
178
179 public function getNotnull(): bool
180 {
181 return $this->_notnull;
182 }
183
184 public function getDefault(): mixed
185 {
186 return $this->_default;
187 }
188
189 /** @return array<string, mixed> */
190 public function getPlatformOptions(): array
191 {
192 return $this->_platformOptions;
193 }
194
195 public function hasPlatformOption(string $name): bool
196 {
197 return isset($this->_platformOptions[$name]);
198 }
199
200 public function getPlatformOption(string $name): mixed
201 {
202 return $this->_platformOptions[$name];
203 }
204
205 public function getColumnDefinition(): ?string
206 {
207 return $this->_columnDefinition;
208 }
209
210 public function getAutoincrement(): bool
211 {
212 return $this->_autoincrement;
213 }
214
215 public function setAutoincrement(bool $flag): self
216 {
217 $this->_autoincrement = $flag;
218
219 return $this;
220 }
221
222 public function setComment(string $comment): self
223 {
224 $this->_comment = $comment;
225
226 return $this;
227 }
228
229 public function getComment(): string
230 {
231 return $this->_comment;
232 }
233
234 /** @return array<string, mixed> */
235 public function toArray(): array
236 {
237 return array_merge([
238 'name' => $this->_name,
239 'type' => $this->_type,
240 'default' => $this->_default,
241 'notnull' => $this->_notnull,
242 'length' => $this->_length,
243 'precision' => $this->_precision,
244 'scale' => $this->_scale,
245 'fixed' => $this->_fixed,
246 'unsigned' => $this->_unsigned,
247 'autoincrement' => $this->_autoincrement,
248 'columnDefinition' => $this->_columnDefinition,
249 'comment' => $this->_comment,
250 ], $this->_platformOptions);
251 }
252}