diff options
author | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
commit | bf6655a534a6775d30cafa67bd801276bda1d98d (patch) | |
tree | c6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/doctrine/orm/src/Mapping/Builder/FieldBuilder.php | |
parent | 94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff) | |
download | AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip |
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/doctrine/orm/src/Mapping/Builder/FieldBuilder.php')
-rw-r--r-- | vendor/doctrine/orm/src/Mapping/Builder/FieldBuilder.php | 243 |
1 files changed, 243 insertions, 0 deletions
diff --git a/vendor/doctrine/orm/src/Mapping/Builder/FieldBuilder.php b/vendor/doctrine/orm/src/Mapping/Builder/FieldBuilder.php new file mode 100644 index 0000000..8326ff5 --- /dev/null +++ b/vendor/doctrine/orm/src/Mapping/Builder/FieldBuilder.php | |||
@@ -0,0 +1,243 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Doctrine\ORM\Mapping\Builder; | ||
6 | |||
7 | use function constant; | ||
8 | |||
9 | /** | ||
10 | * Field Builder | ||
11 | * | ||
12 | * @link www.doctrine-project.com | ||
13 | */ | ||
14 | class FieldBuilder | ||
15 | { | ||
16 | private bool $version = false; | ||
17 | private string|null $generatedValue = null; | ||
18 | |||
19 | /** @var mixed[]|null */ | ||
20 | private array|null $sequenceDef = null; | ||
21 | |||
22 | private string|null $customIdGenerator = null; | ||
23 | |||
24 | /** @param mixed[] $mapping */ | ||
25 | public function __construct( | ||
26 | private readonly ClassMetadataBuilder $builder, | ||
27 | private array $mapping, | ||
28 | ) { | ||
29 | } | ||
30 | |||
31 | /** | ||
32 | * Sets length. | ||
33 | * | ||
34 | * @return $this | ||
35 | */ | ||
36 | public function length(int $length): static | ||
37 | { | ||
38 | $this->mapping['length'] = $length; | ||
39 | |||
40 | return $this; | ||
41 | } | ||
42 | |||
43 | /** | ||
44 | * Sets nullable. | ||
45 | * | ||
46 | * @return $this | ||
47 | */ | ||
48 | public function nullable(bool $flag = true): static | ||
49 | { | ||
50 | $this->mapping['nullable'] = $flag; | ||
51 | |||
52 | return $this; | ||
53 | } | ||
54 | |||
55 | /** | ||
56 | * Sets Unique. | ||
57 | * | ||
58 | * @return $this | ||
59 | */ | ||
60 | public function unique(bool $flag = true): static | ||
61 | { | ||
62 | $this->mapping['unique'] = $flag; | ||
63 | |||
64 | return $this; | ||
65 | } | ||
66 | |||
67 | /** | ||
68 | * Sets column name. | ||
69 | * | ||
70 | * @return $this | ||
71 | */ | ||
72 | public function columnName(string $name): static | ||
73 | { | ||
74 | $this->mapping['columnName'] = $name; | ||
75 | |||
76 | return $this; | ||
77 | } | ||
78 | |||
79 | /** | ||
80 | * Sets Precision. | ||
81 | * | ||
82 | * @return $this | ||
83 | */ | ||
84 | public function precision(int $p): static | ||
85 | { | ||
86 | $this->mapping['precision'] = $p; | ||
87 | |||
88 | return $this; | ||
89 | } | ||
90 | |||
91 | /** | ||
92 | * Sets insertable. | ||
93 | * | ||
94 | * @return $this | ||
95 | */ | ||
96 | public function insertable(bool $flag = true): self | ||
97 | { | ||
98 | if (! $flag) { | ||
99 | $this->mapping['notInsertable'] = true; | ||
100 | } | ||
101 | |||
102 | return $this; | ||
103 | } | ||
104 | |||
105 | /** | ||
106 | * Sets updatable. | ||
107 | * | ||
108 | * @return $this | ||
109 | */ | ||
110 | public function updatable(bool $flag = true): self | ||
111 | { | ||
112 | if (! $flag) { | ||
113 | $this->mapping['notUpdatable'] = true; | ||
114 | } | ||
115 | |||
116 | return $this; | ||
117 | } | ||
118 | |||
119 | /** | ||
120 | * Sets scale. | ||
121 | * | ||
122 | * @return $this | ||
123 | */ | ||
124 | public function scale(int $s): static | ||
125 | { | ||
126 | $this->mapping['scale'] = $s; | ||
127 | |||
128 | return $this; | ||
129 | } | ||
130 | |||
131 | /** | ||
132 | * Sets field as primary key. | ||
133 | * | ||
134 | * @return $this | ||
135 | */ | ||
136 | public function makePrimaryKey(): static | ||
137 | { | ||
138 | $this->mapping['id'] = true; | ||
139 | |||
140 | return $this; | ||
141 | } | ||
142 | |||
143 | /** | ||
144 | * Sets an option. | ||
145 | * | ||
146 | * @return $this | ||
147 | */ | ||
148 | public function option(string $name, mixed $value): static | ||
149 | { | ||
150 | $this->mapping['options'][$name] = $value; | ||
151 | |||
152 | return $this; | ||
153 | } | ||
154 | |||
155 | /** @return $this */ | ||
156 | public function generatedValue(string $strategy = 'AUTO'): static | ||
157 | { | ||
158 | $this->generatedValue = $strategy; | ||
159 | |||
160 | return $this; | ||
161 | } | ||
162 | |||
163 | /** | ||
164 | * Sets field versioned. | ||
165 | * | ||
166 | * @return $this | ||
167 | */ | ||
168 | public function isVersionField(): static | ||
169 | { | ||
170 | $this->version = true; | ||
171 | |||
172 | return $this; | ||
173 | } | ||
174 | |||
175 | /** | ||
176 | * Sets Sequence Generator. | ||
177 | * | ||
178 | * @return $this | ||
179 | */ | ||
180 | public function setSequenceGenerator(string $sequenceName, int $allocationSize = 1, int $initialValue = 1): static | ||
181 | { | ||
182 | $this->sequenceDef = [ | ||
183 | 'sequenceName' => $sequenceName, | ||
184 | 'allocationSize' => $allocationSize, | ||
185 | 'initialValue' => $initialValue, | ||
186 | ]; | ||
187 | |||
188 | return $this; | ||
189 | } | ||
190 | |||
191 | /** | ||
192 | * Sets column definition. | ||
193 | * | ||
194 | * @return $this | ||
195 | */ | ||
196 | public function columnDefinition(string $def): static | ||
197 | { | ||
198 | $this->mapping['columnDefinition'] = $def; | ||
199 | |||
200 | return $this; | ||
201 | } | ||
202 | |||
203 | /** | ||
204 | * Set the FQCN of the custom ID generator. | ||
205 | * This class must extend \Doctrine\ORM\Id\AbstractIdGenerator. | ||
206 | * | ||
207 | * @return $this | ||
208 | */ | ||
209 | public function setCustomIdGenerator(string $customIdGenerator): static | ||
210 | { | ||
211 | $this->customIdGenerator = $customIdGenerator; | ||
212 | |||
213 | return $this; | ||
214 | } | ||
215 | |||
216 | /** | ||
217 | * Finalizes this field and attach it to the ClassMetadata. | ||
218 | * | ||
219 | * Without this call a FieldBuilder has no effect on the ClassMetadata. | ||
220 | */ | ||
221 | public function build(): ClassMetadataBuilder | ||
222 | { | ||
223 | $cm = $this->builder->getClassMetadata(); | ||
224 | if ($this->generatedValue) { | ||
225 | $cm->setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_' . $this->generatedValue)); | ||
226 | } | ||
227 | |||
228 | if ($this->version) { | ||
229 | $cm->setVersionMapping($this->mapping); | ||
230 | } | ||
231 | |||
232 | $cm->mapField($this->mapping); | ||
233 | if ($this->sequenceDef) { | ||
234 | $cm->setSequenceGeneratorDefinition($this->sequenceDef); | ||
235 | } | ||
236 | |||
237 | if ($this->customIdGenerator) { | ||
238 | $cm->setCustomGeneratorDefinition(['class' => $this->customIdGenerator]); | ||
239 | } | ||
240 | |||
241 | return $this->builder; | ||
242 | } | ||
243 | } | ||