[TASK] Harden \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / Generic / Mapper / ColumnMap.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Extbase\Persistence\Generic\Mapper;
5
6 /*
7 * This file is part of the TYPO3 CMS project.
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 /**
20 * A column map to map a column configured in $TCA on a property of a domain object.
21 * @internal only to be used within Extbase, not part of TYPO3 Core API.
22 */
23 class ColumnMap
24 {
25 /**
26 * Constants reflecting the type of relation
27 */
28 const RELATION_NONE = 'RELATION_NONE';
29 const RELATION_HAS_ONE = 'RELATION_HAS_ONE';
30 const RELATION_HAS_MANY = 'RELATION_HAS_MANY';
31 const RELATION_BELONGS_TO_MANY = 'RELATION_BELONGS_TO_MANY';
32 const RELATION_HAS_AND_BELONGS_TO_MANY = 'RELATION_HAS_AND_BELONGS_TO_MANY';
33
34 /**
35 * Constants reflecting how the relation information is stored
36 */
37 const RELATION_PARENT_FOREIGN_KEY = 'RELATION_PARENT_FOREIGN_KEY';
38 const RELATION_CHILD_FOREIGN_KEY = 'RELATION_CHILD_FOREIGN_KEY';
39 const RELATION_PARENT_CSV = 'RELATION_PARENT_CSV';
40 const RELATION_INTERMEDIATE_TABLE = 'RELATION_INTERMEDIATE_TABLE';
41
42 /**
43 * Constants reflecting the loading strategy
44 */
45 const STRATEGY_EAGER = 'eager';
46 const STRATEGY_LAZY_PROXY = 'proxy';
47 const STRATEGY_LAZY_STORAGE = 'storage';
48
49 /**
50 * The property name corresponding to the table name
51 *
52 * @var string
53 */
54 protected $propertyName;
55
56 /**
57 * The column name
58 *
59 * @var string
60 */
61 protected $columnName;
62
63 /**
64 * todo: Check if this property should support null. If not, set default value.
65 * The type of relation
66 *
67 * @var string|null
68 */
69 protected $typeOfRelation;
70
71 /**
72 * todo: property is not in use, can be dropped
73 * The name of the child's class
74 *
75 * @var string
76 */
77 protected $childClassName;
78
79 /**
80 * todo: Check if this property should support null. If not, set default value.
81 * The name of the child's table
82 *
83 * @var string|null
84 */
85 protected $childTableName;
86
87 /**
88 * todo: Check if this property should support null. If not, set default value.
89 * The where clause to narrow down the selected child records
90 *
91 * @var string|null
92 */
93 protected $childTableWhereStatement;
94
95 /**
96 * todo: Check if this property should support null. If not, set default value.
97 * The name of the field the results from the child's table are sorted by
98 *
99 * @var string|null
100 */
101 protected $childSortByFieldName;
102
103 /**
104 * todo: Check if this property should support null. If not, set default value.
105 * The name of the relation table
106 *
107 * @var string|null
108 */
109 protected $relationTableName;
110
111 /**
112 * todo: Check if this property should support null. If not, set default value.
113 * The name of the column of the relation table holding the page id
114 *
115 * @var string|null
116 */
117 protected $relationTablePageIdColumnName;
118
119 /**
120 * todo: Check if this property should support null. If not, set default value.
121 * An array of field => value pairs to both insert and match against when writing/reading MM relations
122 *
123 * @var array|null
124 */
125 protected $relationTableMatchFields;
126
127 /**
128 * todo: Check if this property should support null. If not, set default value.
129 * Array of field=>value pairs to insert when writing new MM relations
130 *
131 * @var array|null
132 */
133 protected $relationTableInsertFields;
134
135 /**
136 * todo: Check if this property should support null. If not, set default value.
137 * The where clause to narrow down the selected relation table records
138 *
139 * @var string|null
140 */
141 protected $relationTableWhereStatement;
142
143 /**
144 * todo: Check if this property should support null. If not, set default value.
145 * The name of the field holding the parents key
146 *
147 * @var string|null
148 */
149 protected $parentKeyFieldName;
150
151 /**
152 * todo: Check if this property should support null. If not, set default value.
153 * The name of the field holding the name of the table of the parent's records
154 *
155 * @var string|null
156 */
157 protected $parentTableFieldName;
158
159 /**
160 * todo: Check if this property should support null. If not, set default value.
161 * The name of the field holding the children key
162 *
163 * @var string|null
164 */
165 protected $childKeyFieldName;
166
167 /**
168 * todo: Check if this property should support null. If not, set default value.
169 * Alternative format for storing DataTime formats
170 * (instead of using unix-time stamps). Allowed values
171 * are 'date', 'datetime' and 'time'
172 *
173 * @var string|null
174 */
175 protected $dateTimeStorageFormat;
176
177 /**
178 * todo: Check if this property should support null. If not, set default value.
179 * @var \TYPO3\CMS\Core\DataHandling\TableColumnType|null
180 */
181 protected $type;
182
183 /**
184 * todo: Check if this property should support null. If not, set default value.
185 * @var \TYPO3\CMS\Core\DataHandling\TableColumnSubType|null
186 */
187 protected $internalType;
188
189 /**
190 * Constructs a Column Map
191 *
192 * @param string $columnName The column name
193 * @param string $propertyName The property name
194 */
195 public function __construct(string $columnName, string $propertyName)
196 {
197 // @todo Enable aliases (tx_anotherextension_addedcolumn -> theAddedColumn)
198 $this->columnName = $columnName;
199 $this->propertyName = $propertyName;
200 }
201
202 /**
203 * @param string $typeOfRelation
204 */
205 public function setTypeOfRelation(string $typeOfRelation): void
206 {
207 $this->typeOfRelation = $typeOfRelation;
208 }
209
210 /**
211 * @return string
212 */
213 public function getTypeOfRelation(): string
214 {
215 return $this->typeOfRelation;
216 }
217
218 /**
219 * todo: The property name of column maps should be immutable, therefore this setter must be dropped
220 * @param string $propertyName
221 */
222 public function setPropertyName(string $propertyName): void
223 {
224 $this->propertyName = $propertyName;
225 }
226
227 /**
228 * @return string
229 */
230 public function getPropertyName(): string
231 {
232 return $this->propertyName;
233 }
234
235 /**
236 * todo: The column name of column maps should be immutable, therefore this setter must be dropped
237 * @param string $columnName
238 */
239 public function setColumnName(string $columnName): void
240 {
241 $this->columnName = $columnName;
242 }
243
244 /**
245 * @return string
246 */
247 public function getColumnName(): string
248 {
249 return $this->columnName;
250 }
251
252 /**
253 * @param string|null $childTableName
254 */
255 public function setChildTableName(?string $childTableName): void
256 {
257 $this->childTableName = $childTableName;
258 }
259
260 /**
261 * @return string|null
262 */
263 public function getChildTableName(): ?string
264 {
265 return $this->childTableName;
266 }
267
268 /**
269 * @param string|null $childTableWhereStatement
270 */
271 public function setChildTableWhereStatement(?string $childTableWhereStatement): void
272 {
273 $this->childTableWhereStatement = $childTableWhereStatement;
274 }
275
276 /**
277 * @return string|null
278 */
279 public function getChildTableWhereStatement(): ?string
280 {
281 return $this->childTableWhereStatement;
282 }
283
284 /**
285 * @param string|null $childSortByFieldName
286 */
287 public function setChildSortByFieldName(?string $childSortByFieldName): void
288 {
289 $this->childSortByFieldName = $childSortByFieldName;
290 }
291
292 /**
293 * @return string|null
294 */
295 public function getChildSortByFieldName(): ?string
296 {
297 return $this->childSortByFieldName;
298 }
299
300 /**
301 * @param string|null $relationTableName
302 */
303 public function setRelationTableName(?string $relationTableName): void
304 {
305 $this->relationTableName = $relationTableName;
306 }
307
308 /**
309 * @return string|null
310 */
311 public function getRelationTableName(): ?string
312 {
313 return $this->relationTableName;
314 }
315
316 /**
317 * @param string $relationTablePageIdColumnName
318 */
319 public function setRelationTablePageIdColumnName(string $relationTablePageIdColumnName): void
320 {
321 $this->relationTablePageIdColumnName = $relationTablePageIdColumnName;
322 }
323
324 /**
325 * @return string|null
326 */
327 public function getRelationTablePageIdColumnName(): ?string
328 {
329 return $this->relationTablePageIdColumnName;
330 }
331
332 /**
333 * @param array|null $relationTableMatchFields
334 */
335 public function setRelationTableMatchFields(?array $relationTableMatchFields): void
336 {
337 $this->relationTableMatchFields = $relationTableMatchFields;
338 }
339
340 /**
341 * @return array|null
342 */
343 public function getRelationTableMatchFields(): ?array
344 {
345 return $this->relationTableMatchFields;
346 }
347
348 /**
349 * @param array $relationTableInsertFields
350 */
351 public function setRelationTableInsertFields(array $relationTableInsertFields): void
352 {
353 $this->relationTableInsertFields = $relationTableInsertFields;
354 }
355
356 /**
357 * @return array|null
358 */
359 public function getRelationTableInsertFields(): ?array
360 {
361 return $this->relationTableInsertFields;
362 }
363
364 /**
365 * @param string|null $relationTableWhereStatement
366 */
367 public function setRelationTableWhereStatement(?string $relationTableWhereStatement): void
368 {
369 $this->relationTableWhereStatement = $relationTableWhereStatement;
370 }
371
372 /**
373 * @return string|null
374 */
375 public function getRelationTableWhereStatement(): ?string
376 {
377 return $this->relationTableWhereStatement;
378 }
379
380 /**
381 * @param string|null $parentKeyFieldName
382 */
383 public function setParentKeyFieldName(?string $parentKeyFieldName): void
384 {
385 $this->parentKeyFieldName = $parentKeyFieldName;
386 }
387
388 /**
389 * @return string|null
390 */
391 public function getParentKeyFieldName(): ?string
392 {
393 return $this->parentKeyFieldName;
394 }
395
396 /**
397 * @param string|null $parentTableFieldName
398 */
399 public function setParentTableFieldName(?string $parentTableFieldName): void
400 {
401 $this->parentTableFieldName = $parentTableFieldName;
402 }
403
404 /**
405 * @return string|null
406 */
407 public function getParentTableFieldName(): ?string
408 {
409 return $this->parentTableFieldName;
410 }
411
412 /**
413 * @param string $childKeyFieldName
414 */
415 public function setChildKeyFieldName(string $childKeyFieldName): void
416 {
417 $this->childKeyFieldName = $childKeyFieldName;
418 }
419
420 /**
421 * @return string|null
422 */
423 public function getChildKeyFieldName(): ?string
424 {
425 return $this->childKeyFieldName;
426 }
427
428 /**
429 * @param string|null $dateTimeStorageFormat
430 */
431 public function setDateTimeStorageFormat(?string $dateTimeStorageFormat): void
432 {
433 $this->dateTimeStorageFormat = $dateTimeStorageFormat;
434 }
435
436 /**
437 * @return string|null
438 */
439 public function getDateTimeStorageFormat(): ?string
440 {
441 return $this->dateTimeStorageFormat;
442 }
443
444 /**
445 * @param \TYPO3\CMS\Core\DataHandling\TableColumnSubType $internalType
446 */
447 public function setInternalType(\TYPO3\CMS\Core\DataHandling\TableColumnSubType $internalType): void
448 {
449 $this->internalType = $internalType;
450 }
451
452 /**
453 * @return \TYPO3\CMS\Core\DataHandling\TableColumnSubType|null
454 */
455 public function getInternalType(): ?\TYPO3\CMS\Core\DataHandling\TableColumnSubType
456 {
457 return $this->internalType;
458 }
459
460 /**
461 * @param \TYPO3\CMS\Core\DataHandling\TableColumnType $type
462 */
463 public function setType(\TYPO3\CMS\Core\DataHandling\TableColumnType $type): void
464 {
465 $this->type = $type;
466 }
467
468 /**
469 * @return \TYPO3\CMS\Core\DataHandling\TableColumnType|null
470 */
471 public function getType(): ?\TYPO3\CMS\Core\DataHandling\TableColumnType
472 {
473 return $this->type;
474 }
475 }