1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\ORM\Mapping; |
6
|
|
|
|
7
|
|
|
use ArrayIterator; |
8
|
|
|
use Doctrine\ORM\Cache\Exception\CacheException; |
9
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
10
|
|
|
use Doctrine\ORM\Reflection\ReflectionService; |
11
|
|
|
use Doctrine\ORM\Sequencing\Planning\ValueGenerationPlan; |
12
|
|
|
use Doctrine\ORM\Utility\PersisterHelper; |
13
|
|
|
use ReflectionException; |
14
|
|
|
use RuntimeException; |
15
|
|
|
use function array_filter; |
16
|
|
|
use function array_merge; |
17
|
|
|
use function class_exists; |
18
|
|
|
use function get_class; |
19
|
|
|
use function in_array; |
20
|
|
|
use function interface_exists; |
21
|
|
|
use function is_subclass_of; |
22
|
|
|
use function method_exists; |
23
|
|
|
use function spl_object_id; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* A <tt>ClassMetadata</tt> instance holds all the object-relational mapping metadata |
27
|
|
|
* of an entity and its associations. |
28
|
|
|
*/ |
29
|
|
|
class ClassMetadata extends ComponentMetadata implements TableOwner |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* The name of the custom repository class used for the entity class. |
33
|
|
|
* (Optional). |
34
|
|
|
* |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected $customRepositoryClassName; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* READ-ONLY: Whether this class describes the mapping of a mapped superclass. |
41
|
|
|
* |
42
|
|
|
* @var bool |
43
|
|
|
*/ |
44
|
|
|
public $isMappedSuperclass = false; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* READ-ONLY: Whether this class describes the mapping of an embeddable class. |
48
|
|
|
* |
49
|
|
|
* @var bool |
50
|
|
|
*/ |
51
|
|
|
public $isEmbeddedClass = false; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Whether this class describes the mapping of a read-only class. |
55
|
|
|
* That means it is never considered for change-tracking in the UnitOfWork. |
56
|
|
|
* It is a very helpful performance optimization for entities that are immutable, |
57
|
|
|
* either in your domain or through the relation database (coming from a view, |
58
|
|
|
* or a history table for example). |
59
|
|
|
* |
60
|
|
|
* @var bool |
61
|
|
|
*/ |
62
|
|
|
private $readOnly = false; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* The names of all subclasses (descendants). |
66
|
|
|
* |
67
|
|
|
* @var string[] |
68
|
|
|
*/ |
69
|
|
|
protected $subClasses = []; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* READ-ONLY: The names of all embedded classes based on properties. |
73
|
|
|
* |
74
|
|
|
* @var string[] |
75
|
|
|
*/ |
76
|
|
|
//public $embeddedClasses = []; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* READ-ONLY: The registered lifecycle callbacks for entities of this class. |
80
|
|
|
* |
81
|
|
|
* @var string[][] |
82
|
|
|
*/ |
83
|
|
|
public $lifecycleCallbacks = []; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* READ-ONLY: The registered entity listeners. |
87
|
|
|
* |
88
|
|
|
* @var mixed[][] |
89
|
|
|
*/ |
90
|
|
|
public $entityListeners = []; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* READ-ONLY: The field names of all fields that are part of the identifier/primary key |
94
|
|
|
* of the mapped entity class. |
95
|
|
|
* |
96
|
|
|
* @var string[] |
97
|
|
|
*/ |
98
|
|
|
public $identifier = []; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* READ-ONLY: The inheritance mapping type used by the class. |
102
|
|
|
* |
103
|
|
|
* @var string |
104
|
|
|
*/ |
105
|
|
|
public $inheritanceType = InheritanceType::NONE; |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* READ-ONLY: The policy used for change-tracking on entities of this class. |
109
|
|
|
* |
110
|
|
|
* @var string |
111
|
|
|
*/ |
112
|
|
|
public $changeTrackingPolicy = ChangeTrackingPolicy::DEFERRED_IMPLICIT; |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* READ-ONLY: The discriminator value of this class. |
116
|
|
|
* |
117
|
|
|
* <b>This does only apply to the JOINED and SINGLE_TABLE inheritance mapping strategies |
118
|
|
|
* where a discriminator column is used.</b> |
119
|
|
|
* |
120
|
|
|
* @see discriminatorColumn |
121
|
|
|
* |
122
|
|
|
* @var mixed |
123
|
|
|
*/ |
124
|
|
|
public $discriminatorValue; |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* READ-ONLY: The discriminator map of all mapped classes in the hierarchy. |
128
|
|
|
* |
129
|
|
|
* <b>This does only apply to the JOINED and SINGLE_TABLE inheritance mapping strategies |
130
|
|
|
* where a discriminator column is used.</b> |
131
|
|
|
* |
132
|
|
|
* @see discriminatorColumn |
133
|
|
|
* |
134
|
|
|
* @var string[] |
135
|
|
|
*/ |
136
|
|
|
public $discriminatorMap = []; |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* READ-ONLY: The definition of the discriminator column used in JOINED and SINGLE_TABLE |
140
|
|
|
* inheritance mappings. |
141
|
|
|
* |
142
|
|
|
* @var DiscriminatorColumnMetadata |
143
|
|
|
*/ |
144
|
|
|
public $discriminatorColumn; |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* READ-ONLY: The primary table metadata. |
148
|
|
|
* |
149
|
|
|
* @var TableMetadata |
150
|
|
|
*/ |
151
|
|
|
public $table; |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* READ-ONLY: An array of field names. Used to look up field names from column names. |
155
|
|
|
* Keys are column names and values are field names. |
156
|
|
|
* |
157
|
|
|
* @var string[] |
158
|
|
|
*/ |
159
|
|
|
public $fieldNames = []; |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* READ-ONLY: The field which is used for versioning in optimistic locking (if any). |
163
|
|
|
* |
164
|
|
|
* @var FieldMetadata|null |
165
|
|
|
*/ |
166
|
|
|
public $versionProperty; |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Value generation plan is responsible for generating values for auto-generated fields. |
170
|
|
|
* |
171
|
|
|
* @var ValueGenerationPlan |
172
|
|
|
*/ |
173
|
|
|
protected $valueGenerationPlan; |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Initializes a new ClassMetadata instance that will hold the object-relational mapping |
177
|
|
|
* metadata of the class with the given name. |
178
|
|
|
* |
179
|
|
|
* @param string $entityName The name of the entity class. |
180
|
|
|
* @param ClassMetadata|null $parent Optional parent class metadata. |
181
|
|
|
*/ |
182
|
450 |
|
public function __construct(string $entityName, ?ComponentMetadata $parent) |
183
|
|
|
{ |
184
|
450 |
|
parent::__construct($entityName); |
185
|
|
|
|
186
|
450 |
|
if ($parent) { |
187
|
99 |
|
$this->setParent($parent); |
188
|
|
|
} |
189
|
450 |
|
} |
190
|
|
|
|
191
|
|
|
/** |
|
|
|
|
192
|
|
|
* {@inheritdoc} |
193
|
|
|
* |
194
|
|
|
* @throws MappingException |
|
|
|
|
195
|
|
|
*/ |
|
|
|
|
196
|
99 |
|
public function setParent(ComponentMetadata $parent) : void |
197
|
|
|
{ |
198
|
99 |
|
parent::setParent($parent); |
199
|
|
|
|
200
|
99 |
|
foreach ($parent->getPropertiesIterator() as $fieldName => $property) { |
201
|
96 |
|
$this->addInheritedProperty($property); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
// @todo guilhermeblanco Assume to be a ClassMetadata temporarily until ClassMetadata split is complete. |
205
|
|
|
/** @var ClassMetadata $parent */ |
206
|
99 |
|
$this->setInheritanceType($parent->inheritanceType); |
|
|
|
|
207
|
99 |
|
$this->setIdentifier($parent->identifier); |
208
|
99 |
|
$this->setChangeTrackingPolicy($parent->changeTrackingPolicy); |
209
|
|
|
|
210
|
99 |
|
if ($parent->discriminatorColumn) { |
211
|
71 |
|
$this->setDiscriminatorColumn($parent->discriminatorColumn); |
212
|
71 |
|
$this->setDiscriminatorMap($parent->discriminatorMap); |
213
|
|
|
} |
214
|
|
|
|
215
|
99 |
|
if ($parent->isMappedSuperclass) { |
216
|
28 |
|
$this->setCustomRepositoryClassName($parent->getCustomRepositoryClassName()); |
217
|
|
|
} |
218
|
|
|
|
219
|
99 |
|
if ($parent->cache) { |
220
|
3 |
|
$this->setCache(clone $parent->cache); |
221
|
|
|
} |
222
|
|
|
|
223
|
99 |
|
if (! empty($parent->lifecycleCallbacks)) { |
224
|
5 |
|
$this->lifecycleCallbacks = $parent->lifecycleCallbacks; |
225
|
|
|
} |
226
|
|
|
|
227
|
99 |
|
if (! empty($parent->entityListeners)) { |
228
|
7 |
|
$this->entityListeners = $parent->entityListeners; |
229
|
|
|
} |
230
|
99 |
|
} |
231
|
|
|
|
232
|
|
|
public function setClassName(string $className) |
|
|
|
|
233
|
|
|
{ |
234
|
|
|
$this->className = $className; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
public function getColumnsIterator() : ArrayIterator |
|
|
|
|
238
|
|
|
{ |
239
|
|
|
$iterator = parent::getColumnsIterator(); |
240
|
|
|
|
241
|
|
|
if ($this->discriminatorColumn) { |
242
|
|
|
$iterator->offsetSet($this->discriminatorColumn->getColumnName(), $this->discriminatorColumn); |
|
|
|
|
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
return $iterator; |
246
|
|
|
} |
247
|
|
|
|
248
|
11 |
|
public function getAncestorsIterator() : ArrayIterator |
|
|
|
|
249
|
|
|
{ |
250
|
11 |
|
$ancestors = new ArrayIterator(); |
251
|
11 |
|
$parent = $this; |
252
|
|
|
|
253
|
11 |
|
while (($parent = $parent->parent) !== null) { |
254
|
8 |
|
if ($parent instanceof ClassMetadata && $parent->isMappedSuperclass) { |
255
|
1 |
|
continue; |
256
|
|
|
} |
257
|
|
|
|
258
|
7 |
|
$ancestors->append($parent); |
259
|
|
|
} |
260
|
|
|
|
261
|
11 |
|
return $ancestors; |
262
|
|
|
} |
263
|
|
|
|
264
|
1260 |
|
public function getRootClassName() : string |
|
|
|
|
265
|
|
|
{ |
266
|
1260 |
|
$rootClass = $parentClass = $this; |
267
|
1260 |
|
while (($parentClass = $parentClass->getParent()) !== null) { |
268
|
404 |
|
if (! $parentClass->isMappedSuperclass) { |
269
|
402 |
|
$rootClass = $parentClass; |
270
|
|
|
} |
271
|
|
|
} |
272
|
|
|
|
273
|
1260 |
|
return $rootClass->className; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* Handles metadata cloning nicely. |
278
|
|
|
*/ |
|
|
|
|
279
|
12 |
|
public function __clone() |
280
|
|
|
{ |
281
|
12 |
|
if ($this->cache) { |
282
|
12 |
|
$this->cache = clone $this->cache; |
283
|
|
|
} |
284
|
|
|
|
285
|
12 |
|
foreach ($this->properties as $name => $property) { |
286
|
12 |
|
$this->properties[$name] = clone $property; |
287
|
|
|
} |
288
|
12 |
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* Creates a string representation of this instance. |
292
|
|
|
* |
293
|
|
|
* @return string The string representation of this instance. |
294
|
|
|
* |
295
|
|
|
* @todo Construct meaningful string representation. |
296
|
|
|
*/ |
297
|
|
|
public function __toString() |
|
|
|
|
298
|
|
|
{ |
299
|
|
|
return self::class . '@' . spl_object_id($this); |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* Determines which fields get serialized. |
304
|
|
|
* |
305
|
|
|
* It is only serialized what is necessary for best unserialization performance. |
306
|
|
|
* That means any metadata properties that are not set or empty or simply have |
307
|
|
|
* their default value are NOT serialized. |
308
|
|
|
* |
309
|
|
|
* Parts that are also NOT serialized because they can not be properly unserialized: |
310
|
|
|
* - reflectionClass |
311
|
|
|
* |
312
|
|
|
* @return string[] The names of all the fields that should be serialized. |
313
|
|
|
*/ |
314
|
4 |
|
public function __sleep() |
|
|
|
|
315
|
|
|
{ |
316
|
4 |
|
$serialized = []; |
317
|
|
|
|
318
|
|
|
// This metadata is always serialized/cached. |
319
|
4 |
|
$serialized = array_merge($serialized, [ |
320
|
4 |
|
'properties', |
|
|
|
|
321
|
|
|
'fieldNames', |
|
|
|
|
322
|
|
|
//'embeddedClasses', |
323
|
|
|
'identifier', |
|
|
|
|
324
|
|
|
'className', |
|
|
|
|
325
|
|
|
'parent', |
|
|
|
|
326
|
|
|
'table', |
|
|
|
|
327
|
|
|
'valueGenerationPlan', |
|
|
|
|
328
|
|
|
]); |
|
|
|
|
329
|
|
|
|
330
|
|
|
// The rest of the metadata is only serialized if necessary. |
331
|
4 |
|
if ($this->changeTrackingPolicy !== ChangeTrackingPolicy::DEFERRED_IMPLICIT) { |
332
|
|
|
$serialized[] = 'changeTrackingPolicy'; |
333
|
|
|
} |
334
|
|
|
|
335
|
4 |
|
if ($this->customRepositoryClassName) { |
336
|
1 |
|
$serialized[] = 'customRepositoryClassName'; |
337
|
|
|
} |
338
|
|
|
|
339
|
4 |
|
if ($this->inheritanceType !== InheritanceType::NONE) { |
340
|
1 |
|
$serialized[] = 'inheritanceType'; |
341
|
1 |
|
$serialized[] = 'discriminatorColumn'; |
342
|
1 |
|
$serialized[] = 'discriminatorValue'; |
343
|
1 |
|
$serialized[] = 'discriminatorMap'; |
344
|
1 |
|
$serialized[] = 'subClasses'; |
345
|
|
|
} |
346
|
|
|
|
347
|
4 |
|
if ($this->isMappedSuperclass) { |
348
|
|
|
$serialized[] = 'isMappedSuperclass'; |
349
|
|
|
} |
350
|
|
|
|
351
|
4 |
|
if ($this->isEmbeddedClass) { |
352
|
|
|
$serialized[] = 'isEmbeddedClass'; |
353
|
|
|
} |
354
|
|
|
|
355
|
4 |
|
if ($this->isVersioned()) { |
356
|
|
|
$serialized[] = 'versionProperty'; |
357
|
|
|
} |
358
|
|
|
|
359
|
4 |
|
if ($this->lifecycleCallbacks) { |
|
|
|
|
360
|
|
|
$serialized[] = 'lifecycleCallbacks'; |
361
|
|
|
} |
362
|
|
|
|
363
|
4 |
|
if ($this->entityListeners) { |
|
|
|
|
364
|
1 |
|
$serialized[] = 'entityListeners'; |
365
|
|
|
} |
366
|
|
|
|
367
|
4 |
|
if ($this->cache) { |
368
|
|
|
$serialized[] = 'cache'; |
369
|
|
|
} |
370
|
|
|
|
371
|
4 |
|
if ($this->readOnly) { |
372
|
1 |
|
$serialized[] = 'readOnly'; |
373
|
|
|
} |
374
|
|
|
|
375
|
4 |
|
return $serialized; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
|
|
|
|
379
|
|
|
* Sets the change tracking policy used by this class. |
380
|
|
|
*/ |
|
|
|
|
381
|
105 |
|
public function setChangeTrackingPolicy(string $policy) : void |
382
|
|
|
{ |
383
|
105 |
|
$this->changeTrackingPolicy = $policy; |
384
|
105 |
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* Checks whether a field is part of the identifier/primary key field(s). |
388
|
|
|
* |
389
|
|
|
* @param string $fieldName The field name. |
390
|
|
|
* |
391
|
|
|
* @return bool TRUE if the field is part of the table identifier/primary key field(s), FALSE otherwise. |
|
|
|
|
392
|
|
|
*/ |
393
|
1027 |
|
public function isIdentifier(string $fieldName) : bool |
394
|
|
|
{ |
395
|
1027 |
|
if (! $this->identifier) { |
|
|
|
|
396
|
1 |
|
return false; |
397
|
|
|
} |
398
|
|
|
|
399
|
1026 |
|
if (! $this->isIdentifierComposite()) { |
400
|
1022 |
|
return $fieldName === $this->identifier[0]; |
401
|
|
|
} |
402
|
|
|
|
403
|
93 |
|
return in_array($fieldName, $this->identifier, true); |
404
|
|
|
} |
405
|
|
|
|
406
|
1213 |
|
public function isIdentifierComposite() : bool |
|
|
|
|
407
|
|
|
{ |
408
|
1213 |
|
return isset($this->identifier[1]); |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
/** |
412
|
|
|
* Validates Identifier. |
413
|
|
|
* |
414
|
|
|
* @throws MappingException |
|
|
|
|
415
|
|
|
*/ |
|
|
|
|
416
|
368 |
|
public function validateIdentifier() : void |
417
|
|
|
{ |
418
|
368 |
|
if ($this->isMappedSuperclass || $this->isEmbeddedClass) { |
419
|
28 |
|
return; |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
// Verify & complete identifier mapping |
423
|
368 |
|
if (! $this->identifier) { |
|
|
|
|
424
|
2 |
|
throw MappingException::identifierRequired($this->className); |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
$explicitlyGeneratedProperties = array_filter($this->properties, static function (Property $property) : bool { |
428
|
366 |
|
return $property instanceof FieldMetadata |
429
|
366 |
|
&& $property->isPrimaryKey() |
430
|
366 |
|
&& $property->hasValueGenerator(); |
431
|
366 |
|
}); |
432
|
|
|
|
433
|
366 |
|
if ($explicitlyGeneratedProperties && $this->isIdentifierComposite()) { |
|
|
|
|
434
|
|
|
throw MappingException::compositeKeyAssignedIdGeneratorRequired($this->className); |
435
|
|
|
} |
436
|
366 |
|
} |
437
|
|
|
|
438
|
|
|
/** |
|
|
|
|
439
|
|
|
* Validates lifecycle callbacks. |
440
|
|
|
* |
441
|
|
|
* @throws MappingException |
|
|
|
|
442
|
|
|
*/ |
|
|
|
|
443
|
369 |
|
public function validateLifecycleCallbacks(ReflectionService $reflectionService) : void |
444
|
|
|
{ |
445
|
369 |
|
foreach ($this->lifecycleCallbacks as $callbacks) { |
446
|
|
|
/** @var array $callbacks */ |
447
|
10 |
|
foreach ($callbacks as $callbackFuncName) { |
448
|
10 |
|
if (! $reflectionService->hasPublicMethod($this->className, $callbackFuncName)) { |
449
|
1 |
|
throw MappingException::lifecycleCallbackMethodNotFound($this->className, $callbackFuncName); |
450
|
|
|
} |
451
|
|
|
} |
452
|
|
|
} |
453
|
368 |
|
} |
454
|
|
|
|
455
|
|
|
/** |
456
|
|
|
* {@inheritDoc} |
457
|
|
|
*/ |
|
|
|
|
458
|
402 |
|
public function getIdentifierFieldNames() |
459
|
|
|
{ |
460
|
402 |
|
return $this->identifier; |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
/** |
464
|
|
|
* Gets the name of the single id field. Note that this only works on |
465
|
|
|
* entity classes that have a single-field pk. |
466
|
|
|
* |
467
|
|
|
* @return string |
468
|
|
|
* |
469
|
|
|
* @throws MappingException If the class has a composite primary key. |
470
|
|
|
*/ |
471
|
152 |
|
public function getSingleIdentifierFieldName() |
|
|
|
|
472
|
|
|
{ |
473
|
152 |
|
if ($this->isIdentifierComposite()) { |
474
|
1 |
|
throw MappingException::singleIdNotAllowedOnCompositePrimaryKey($this->className); |
475
|
|
|
} |
476
|
|
|
|
477
|
151 |
|
if (! isset($this->identifier[0])) { |
478
|
1 |
|
throw MappingException::noIdDefined($this->className); |
479
|
|
|
} |
480
|
|
|
|
481
|
150 |
|
return $this->identifier[0]; |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
/** |
485
|
|
|
* INTERNAL: |
486
|
|
|
* Sets the mapped identifier/primary key fields of this class. |
487
|
|
|
* Mainly used by the ClassMetadataFactory to assign inherited identifiers. |
488
|
|
|
* |
489
|
|
|
* @param mixed[] $identifier |
|
|
|
|
490
|
|
|
*/ |
|
|
|
|
491
|
101 |
|
public function setIdentifier(array $identifier) |
|
|
|
|
492
|
|
|
{ |
493
|
101 |
|
$this->identifier = $identifier; |
494
|
101 |
|
} |
495
|
|
|
|
496
|
|
|
/** |
497
|
|
|
* {@inheritDoc} |
498
|
|
|
*/ |
|
|
|
|
499
|
1053 |
|
public function getIdentifier() |
500
|
|
|
{ |
501
|
1053 |
|
return $this->identifier; |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
/** |
|
|
|
|
505
|
|
|
* {@inheritDoc} |
506
|
|
|
*/ |
|
|
|
|
507
|
189 |
|
public function hasField($fieldName) |
508
|
|
|
{ |
509
|
189 |
|
return isset($this->properties[$fieldName]) |
510
|
189 |
|
&& $this->properties[$fieldName] instanceof FieldMetadata; |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
/** |
|
|
|
|
514
|
|
|
* Returns an array with identifier column names and their corresponding ColumnMetadata. |
515
|
|
|
* |
516
|
|
|
* @return ColumnMetadata[] |
517
|
|
|
*/ |
518
|
441 |
|
public function getIdentifierColumns(EntityManagerInterface $em) : array |
519
|
|
|
{ |
520
|
441 |
|
$columns = []; |
521
|
|
|
|
522
|
441 |
|
foreach ($this->identifier as $idProperty) { |
523
|
441 |
|
$property = $this->getProperty($idProperty); |
524
|
|
|
|
525
|
441 |
|
if ($property instanceof FieldMetadata) { |
526
|
435 |
|
$columns[$property->getColumnName()] = $property; |
527
|
|
|
|
528
|
435 |
|
continue; |
529
|
|
|
} |
530
|
|
|
|
531
|
|
|
/** @var AssociationMetadata $property */ |
532
|
|
|
|
533
|
|
|
// Association defined as Id field |
534
|
25 |
|
$targetClass = $em->getClassMetadata($property->getTargetEntity()); |
535
|
|
|
|
536
|
25 |
|
if (! $property->isOwningSide()) { |
537
|
|
|
$property = $targetClass->getProperty($property->getMappedBy()); |
|
|
|
|
538
|
|
|
$targetClass = $em->getClassMetadata($property->getTargetEntity()); |
539
|
|
|
} |
540
|
|
|
|
541
|
25 |
|
$joinColumns = $property instanceof ManyToManyAssociationMetadata |
542
|
|
|
? $property->getJoinTable()->getInverseJoinColumns() |
543
|
25 |
|
: $property->getJoinColumns(); |
544
|
|
|
|
545
|
25 |
|
foreach ($joinColumns as $joinColumn) { |
546
|
|
|
/** @var JoinColumnMetadata $joinColumn */ |
547
|
25 |
|
$columnName = $joinColumn->getColumnName(); |
548
|
25 |
|
$referencedColumnName = $joinColumn->getReferencedColumnName(); |
549
|
|
|
|
550
|
25 |
|
if (! $joinColumn->getType()) { |
551
|
13 |
|
$joinColumn->setType(PersisterHelper::getTypeOfColumn($referencedColumnName, $targetClass, $em)); |
552
|
|
|
} |
553
|
|
|
|
554
|
25 |
|
$columns[$columnName] = $joinColumn; |
555
|
|
|
} |
556
|
|
|
} |
557
|
|
|
|
558
|
441 |
|
return $columns; |
559
|
|
|
} |
560
|
|
|
|
561
|
|
|
/** |
562
|
|
|
* Gets the name of the primary table. |
563
|
|
|
*/ |
|
|
|
|
564
|
1570 |
|
public function getTableName() : ?string |
565
|
|
|
{ |
566
|
1570 |
|
return $this->table->getName(); |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
/** |
570
|
|
|
* Gets primary table's schema name. |
571
|
|
|
*/ |
|
|
|
|
572
|
23 |
|
public function getSchemaName() : ?string |
573
|
|
|
{ |
574
|
23 |
|
return $this->table->getSchema(); |
575
|
|
|
} |
576
|
|
|
|
577
|
|
|
/** |
578
|
|
|
* Gets the table name to use for temporary identifier tables of this class. |
579
|
|
|
*/ |
|
|
|
|
580
|
7 |
|
public function getTemporaryIdTableName() : string |
581
|
|
|
{ |
582
|
7 |
|
$schema = $this->getSchemaName() === null |
583
|
6 |
|
? '' |
584
|
7 |
|
: $this->getSchemaName() . '_'; |
585
|
|
|
|
586
|
|
|
// replace dots with underscores because PostgreSQL creates temporary tables in a special schema |
587
|
7 |
|
return $schema . $this->getTableName() . '_id_tmp'; |
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
/** |
591
|
|
|
* Sets the mapped subclasses of this class. |
592
|
|
|
* |
593
|
|
|
* @param string[] $subclasses The names of all mapped subclasses. |
594
|
|
|
* |
595
|
|
|
* @todo guilhermeblanco Only used for ClassMetadataTest. Remove if possible! |
596
|
|
|
*/ |
|
|
|
|
597
|
4 |
|
public function setSubclasses(array $subclasses) : void |
598
|
|
|
{ |
599
|
4 |
|
foreach ($subclasses as $subclass) { |
600
|
3 |
|
$this->subClasses[] = $subclass; |
601
|
|
|
} |
602
|
4 |
|
} |
603
|
|
|
|
604
|
|
|
/** |
605
|
|
|
* @return string[] |
606
|
|
|
*/ |
607
|
1080 |
|
public function getSubClasses() : array |
608
|
|
|
{ |
609
|
1080 |
|
return $this->subClasses; |
610
|
|
|
} |
611
|
|
|
|
612
|
|
|
/** |
613
|
|
|
* Sets the inheritance type used by the class and its subclasses. |
614
|
|
|
* |
615
|
|
|
* @param int $type |
|
|
|
|
616
|
|
|
* |
617
|
|
|
* @throws MappingException |
|
|
|
|
618
|
|
|
*/ |
|
|
|
|
619
|
121 |
|
public function setInheritanceType($type) : void |
|
|
|
|
620
|
|
|
{ |
621
|
121 |
|
if (! $this->isInheritanceType($type)) { |
622
|
|
|
throw MappingException::invalidInheritanceType($this->className, $type); |
623
|
|
|
} |
624
|
|
|
|
625
|
121 |
|
$this->inheritanceType = $type; |
626
|
121 |
|
} |
627
|
|
|
|
628
|
|
|
/** |
|
|
|
|
629
|
|
|
* Sets the override property mapping for an entity relationship. |
630
|
|
|
* |
631
|
|
|
* @throws RuntimeException |
|
|
|
|
632
|
|
|
* @throws MappingException |
|
|
|
|
633
|
|
|
* @throws CacheException |
|
|
|
|
634
|
|
|
*/ |
|
|
|
|
635
|
12 |
|
public function setPropertyOverride(Property $property) : void |
636
|
|
|
{ |
637
|
12 |
|
$fieldName = $property->getName(); |
638
|
|
|
|
639
|
12 |
|
if (! isset($this->properties[$fieldName])) { |
640
|
2 |
|
throw MappingException::invalidOverrideFieldName($this->className, $fieldName); |
641
|
|
|
} |
642
|
|
|
|
643
|
10 |
|
$originalProperty = $this->getProperty($fieldName); |
644
|
10 |
|
$originalPropertyClassName = get_class($originalProperty); |
645
|
|
|
|
646
|
|
|
// If moving from transient to persistent, assume it's a new property |
647
|
10 |
|
if ($originalPropertyClassName === TransientMetadata::class) { |
648
|
1 |
|
unset($this->properties[$fieldName]); |
649
|
|
|
|
650
|
1 |
|
$this->addProperty($property); |
651
|
|
|
|
652
|
1 |
|
return; |
653
|
|
|
} |
654
|
|
|
|
655
|
|
|
// Do not allow to change property type |
656
|
9 |
|
if ($originalPropertyClassName !== get_class($property)) { |
657
|
|
|
throw MappingException::invalidOverridePropertyType($this->className, $fieldName); |
658
|
|
|
} |
659
|
|
|
|
660
|
|
|
// Do not allow to change version property |
661
|
9 |
|
if ($originalProperty instanceof FieldMetadata && $originalProperty->isVersioned()) { |
662
|
|
|
throw MappingException::invalidOverrideVersionField($this->className, $fieldName); |
663
|
|
|
} |
664
|
|
|
|
665
|
9 |
|
unset($this->properties[$fieldName]); |
666
|
|
|
|
667
|
9 |
|
if ($property instanceof FieldMetadata) { |
668
|
|
|
// Unset defined fieldName prior to override |
669
|
5 |
|
unset($this->fieldNames[$originalProperty->getColumnName()]); |
|
|
|
|
670
|
|
|
|
671
|
|
|
// Revert what should not be allowed to change |
672
|
5 |
|
$property->setDeclaringClass($originalProperty->getDeclaringClass()); |
673
|
5 |
|
$property->setPrimaryKey($originalProperty->isPrimaryKey()); |
674
|
9 |
|
} elseif ($property instanceof AssociationMetadata) { |
675
|
|
|
// Unset all defined fieldNames prior to override |
676
|
9 |
|
if ($originalProperty instanceof ToOneAssociationMetadata && $originalProperty->isOwningSide()) { |
677
|
5 |
|
foreach ($originalProperty->getJoinColumns() as $joinColumn) { |
678
|
5 |
|
unset($this->fieldNames[$joinColumn->getColumnName()]); |
679
|
|
|
} |
680
|
|
|
} |
681
|
|
|
|
682
|
|
|
// Override what it should be allowed to change |
683
|
9 |
|
if ($property->getInversedBy()) { |
684
|
8 |
|
$originalProperty->setInversedBy($property->getInversedBy()); |
|
|
|
|
685
|
|
|
} |
686
|
|
|
|
687
|
9 |
|
if ($property->getFetchMode() !== $originalProperty->getFetchMode()) { |
|
|
|
|
688
|
2 |
|
$originalProperty->setFetchMode($property->getFetchMode()); |
|
|
|
|
689
|
|
|
} |
690
|
|
|
|
691
|
9 |
|
if ($originalProperty instanceof ToOneAssociationMetadata && $property->getJoinColumns()) { |
|
|
|
|
692
|
5 |
|
$originalProperty->setJoinColumns($property->getJoinColumns()); |
693
|
8 |
|
} elseif ($originalProperty instanceof ManyToManyAssociationMetadata && $property->getJoinTable()) { |
|
|
|
|
694
|
8 |
|
$originalProperty->setJoinTable($property->getJoinTable()); |
695
|
|
|
} |
696
|
|
|
|
697
|
9 |
|
$property = $originalProperty; |
698
|
|
|
} |
699
|
|
|
|
700
|
9 |
|
$this->addProperty($property); |
|
|
|
|
701
|
9 |
|
} |
702
|
|
|
|
703
|
|
|
/** |
704
|
|
|
* Checks if this entity is the root in any entity-inheritance-hierarchy. |
705
|
|
|
* |
706
|
|
|
* @return bool |
|
|
|
|
707
|
|
|
*/ |
708
|
336 |
|
public function isRootEntity() |
|
|
|
|
709
|
|
|
{ |
710
|
336 |
|
return $this->className === $this->getRootClassName(); |
711
|
|
|
} |
712
|
|
|
|
713
|
|
|
/** |
714
|
|
|
* Checks whether a mapped field is inherited from a superclass. |
715
|
|
|
* |
716
|
|
|
* @param string $fieldName |
|
|
|
|
717
|
|
|
* |
718
|
|
|
* @return bool TRUE if the field is inherited, FALSE otherwise. |
|
|
|
|
719
|
|
|
*/ |
720
|
622 |
|
public function isInheritedProperty($fieldName) |
|
|
|
|
721
|
|
|
{ |
722
|
622 |
|
$declaringClass = $this->properties[$fieldName]->getDeclaringClass(); |
723
|
622 |
|
if ($declaringClass === $this) { |
|
|
|
|
724
|
614 |
|
return false; |
725
|
363 |
|
} else if (! $declaringClass->isMappedSuperclass) { |
726
|
361 |
|
return true; |
727
|
|
|
} |
728
|
|
|
|
729
|
3 |
|
$parentClass = $this; |
730
|
3 |
|
while (($parentClass = $parentClass->getParent()) !== $declaringClass) { |
731
|
1 |
|
if (! $parentClass->isMappedSuperclass) { |
732
|
1 |
|
return true; |
733
|
|
|
} |
734
|
|
|
} |
735
|
|
|
|
736
|
3 |
|
return false; |
737
|
|
|
} |
738
|
|
|
|
739
|
|
|
/** |
740
|
|
|
* {@inheritdoc} |
741
|
|
|
*/ |
742
|
431 |
|
public function setTable(TableMetadata $table) : void |
743
|
|
|
{ |
744
|
431 |
|
$this->table = $table; |
745
|
|
|
|
746
|
|
|
// Make sure inherited and declared properties reflect newly defined table |
747
|
431 |
|
foreach ($this->properties as $property) { |
748
|
|
|
switch (true) { |
749
|
96 |
|
case $property instanceof FieldMetadata: |
750
|
96 |
|
$property->setTableName($property->getTableName() ?? $table->getName()); |
751
|
96 |
|
break; |
752
|
|
|
|
753
|
42 |
|
case $property instanceof ToOneAssociationMetadata: |
754
|
|
|
// Resolve association join column table names |
755
|
34 |
|
foreach ($property->getJoinColumns() as $joinColumn) { |
756
|
|
|
/** @var JoinColumnMetadata $joinColumn */ |
757
|
34 |
|
$joinColumn->setTableName($joinColumn->getTableName() ?? $table->getName()); |
758
|
|
|
} |
759
|
|
|
|
760
|
34 |
|
break; |
761
|
|
|
} |
762
|
|
|
} |
763
|
431 |
|
} |
764
|
|
|
|
765
|
|
|
/** |
766
|
|
|
* Checks whether the given type identifies an inheritance type. |
767
|
|
|
* |
768
|
|
|
* @param int $type |
769
|
|
|
* |
770
|
|
|
* @return bool TRUE if the given type identifies an inheritance type, FALSe otherwise. |
771
|
|
|
*/ |
772
|
121 |
|
private function isInheritanceType($type) |
773
|
|
|
{ |
774
|
121 |
|
return $type === InheritanceType::NONE |
775
|
94 |
|
|| $type === InheritanceType::SINGLE_TABLE |
776
|
52 |
|
|| $type === InheritanceType::JOINED |
777
|
121 |
|
|| $type === InheritanceType::TABLE_PER_CLASS; |
778
|
|
|
} |
779
|
|
|
|
780
|
916 |
|
public function getColumn(string $columnName) : ?LocalColumnMetadata |
781
|
|
|
{ |
782
|
916 |
|
foreach ($this->properties as $property) { |
783
|
916 |
|
if ($property instanceof LocalColumnMetadata && $property->getColumnName() === $columnName) { |
784
|
916 |
|
return $property; |
785
|
|
|
} |
786
|
|
|
} |
787
|
|
|
|
788
|
|
|
return null; |
789
|
|
|
} |
790
|
|
|
|
791
|
|
|
/** |
792
|
|
|
* Add a property mapping. |
793
|
|
|
* |
794
|
|
|
* @throws RuntimeException |
795
|
|
|
* @throws MappingException |
796
|
|
|
* @throws CacheException |
797
|
|
|
* @throws ReflectionException |
798
|
|
|
*/ |
799
|
418 |
|
public function addProperty(Property $property) : void |
800
|
|
|
{ |
801
|
418 |
|
$fieldName = $property->getName(); |
802
|
|
|
|
803
|
|
|
// Check for empty field name |
804
|
418 |
|
if (empty($fieldName)) { |
805
|
1 |
|
throw MappingException::missingFieldName($this->className); |
806
|
|
|
} |
807
|
|
|
|
808
|
417 |
|
$property->setDeclaringClass($this); |
809
|
|
|
|
810
|
|
|
switch (true) { |
811
|
417 |
|
case $property instanceof FieldMetadata: |
812
|
407 |
|
if ($property->isVersioned()) { |
813
|
20 |
|
$this->versionProperty = $property; |
814
|
|
|
} |
815
|
|
|
|
816
|
407 |
|
$this->fieldNames[$property->getColumnName()] = $property->getName(); |
817
|
407 |
|
break; |
818
|
|
|
|
819
|
275 |
|
case $property instanceof ToOneAssociationMetadata: |
820
|
241 |
|
foreach ($property->getJoinColumns() as $joinColumnMetadata) { |
821
|
233 |
|
$this->fieldNames[$joinColumnMetadata->getColumnName()] = $property->getName(); |
822
|
|
|
} |
823
|
|
|
|
824
|
241 |
|
break; |
825
|
|
|
|
826
|
|
|
default: |
827
|
|
|
// Transient properties are ignored on purpose here! =) |
828
|
178 |
|
break; |
829
|
|
|
} |
830
|
|
|
|
831
|
417 |
|
if ($property->isPrimaryKey() && ! in_array($fieldName, $this->identifier, true)) { |
832
|
396 |
|
$this->identifier[] = $fieldName; |
833
|
|
|
} |
834
|
|
|
|
835
|
417 |
|
parent::addProperty($property); |
836
|
417 |
|
} |
837
|
|
|
|
838
|
|
|
/** |
839
|
|
|
* INTERNAL: |
840
|
|
|
* Adds a property mapping without completing/validating it. |
841
|
|
|
* This is mainly used to add inherited property mappings to derived classes. |
842
|
|
|
*/ |
843
|
97 |
|
public function addInheritedProperty(Property $property) |
844
|
|
|
{ |
845
|
97 |
|
if (isset($this->properties[$property->getName()])) { |
846
|
1 |
|
throw MappingException::duplicateProperty($this->className, $this->getProperty($property->getName())); |
|
|
|
|
847
|
|
|
} |
848
|
|
|
|
849
|
97 |
|
$declaringClass = $property->getDeclaringClass(); |
850
|
97 |
|
$inheritedProperty = $declaringClass->isMappedSuperclass ? clone $property : $property; |
851
|
|
|
|
852
|
97 |
|
if ($inheritedProperty instanceof FieldMetadata) { |
853
|
96 |
|
if (! $declaringClass->isMappedSuperclass) { |
854
|
74 |
|
$inheritedProperty->setTableName($property->getTableName()); |
|
|
|
|
855
|
|
|
} |
856
|
|
|
|
857
|
96 |
|
if ($inheritedProperty->isVersioned()) { |
858
|
4 |
|
$this->versionProperty = $inheritedProperty; |
859
|
|
|
} |
860
|
|
|
|
861
|
96 |
|
$this->fieldNames[$property->getColumnName()] = $property->getName(); |
862
|
43 |
|
} elseif ($inheritedProperty instanceof AssociationMetadata) { |
863
|
42 |
|
if ($declaringClass->isMappedSuperclass) { |
864
|
10 |
|
$inheritedProperty->setSourceEntity($this->className); |
865
|
|
|
} |
866
|
|
|
|
867
|
|
|
// Need to add inherited fieldNames |
868
|
42 |
|
if ($inheritedProperty instanceof ToOneAssociationMetadata && $inheritedProperty->isOwningSide()) { |
869
|
35 |
|
foreach ($inheritedProperty->getJoinColumns() as $joinColumn) { |
870
|
|
|
/** @var JoinColumnMetadata $joinColumn */ |
871
|
34 |
|
$this->fieldNames[$joinColumn->getColumnName()] = $property->getName(); |
872
|
|
|
} |
873
|
|
|
} |
874
|
|
|
} |
875
|
|
|
|
876
|
97 |
|
$this->properties[$property->getName()] = $inheritedProperty; |
877
|
97 |
|
} |
878
|
|
|
|
879
|
|
|
/** |
880
|
|
|
* Registers a custom repository class for the entity class. |
881
|
|
|
* |
882
|
|
|
* @param string|null $repositoryClassName The class name of the custom mapper. |
883
|
|
|
*/ |
884
|
31 |
|
public function setCustomRepositoryClassName(?string $repositoryClassName) |
885
|
|
|
{ |
886
|
31 |
|
$this->customRepositoryClassName = $repositoryClassName; |
887
|
31 |
|
} |
888
|
|
|
|
889
|
164 |
|
public function getCustomRepositoryClassName() : ?string |
890
|
|
|
{ |
891
|
164 |
|
return $this->customRepositoryClassName; |
892
|
|
|
} |
893
|
|
|
|
894
|
|
|
/** |
895
|
|
|
* Whether the class has any attached lifecycle listeners or callbacks for a lifecycle event. |
896
|
|
|
* |
897
|
|
|
* @param string $lifecycleEvent |
898
|
|
|
* |
899
|
|
|
* @return bool |
900
|
|
|
*/ |
901
|
|
|
public function hasLifecycleCallbacks($lifecycleEvent) |
902
|
|
|
{ |
903
|
|
|
return isset($this->lifecycleCallbacks[$lifecycleEvent]); |
904
|
|
|
} |
905
|
|
|
|
906
|
|
|
/** |
907
|
|
|
* Gets the registered lifecycle callbacks for an event. |
908
|
|
|
* |
909
|
|
|
* @param string $event |
910
|
|
|
* |
911
|
|
|
* @return string[] |
912
|
|
|
*/ |
913
|
|
|
public function getLifecycleCallbacks($event) : array |
914
|
|
|
{ |
915
|
|
|
return $this->lifecycleCallbacks[$event] ?? []; |
916
|
|
|
} |
917
|
|
|
|
918
|
|
|
/** |
919
|
|
|
* Adds a lifecycle callback for entities of this class. |
920
|
|
|
*/ |
921
|
16 |
|
public function addLifecycleCallback(string $eventName, string $methodName) |
922
|
|
|
{ |
923
|
16 |
|
if (in_array($methodName, $this->lifecycleCallbacks[$eventName] ?? [], true)) { |
924
|
3 |
|
return; |
925
|
|
|
} |
926
|
|
|
|
927
|
16 |
|
$this->lifecycleCallbacks[$eventName][] = $methodName; |
928
|
16 |
|
} |
929
|
|
|
|
930
|
|
|
/** |
931
|
|
|
* Adds a entity listener for entities of this class. |
932
|
|
|
* |
933
|
|
|
* @param string $eventName The entity lifecycle event. |
934
|
|
|
* @param string $class The listener class. |
935
|
|
|
* @param string $method The listener callback method. |
936
|
|
|
* |
937
|
|
|
* @throws MappingException |
938
|
|
|
*/ |
939
|
13 |
|
public function addEntityListener(string $eventName, string $class, string $methodName) : void |
940
|
|
|
{ |
941
|
|
|
$listener = [ |
942
|
13 |
|
'class' => $class, |
943
|
13 |
|
'method' => $methodName, |
944
|
|
|
]; |
945
|
|
|
|
946
|
13 |
|
if (! class_exists($class)) { |
947
|
1 |
|
throw MappingException::entityListenerClassNotFound($class, $this->className); |
948
|
|
|
} |
949
|
|
|
|
950
|
12 |
|
if (! method_exists($class, $methodName)) { |
951
|
1 |
|
throw MappingException::entityListenerMethodNotFound($class, $methodName, $this->className); |
952
|
|
|
} |
953
|
|
|
|
954
|
|
|
// Check if entity listener already got registered and ignore it if positive |
955
|
11 |
|
if (in_array($listener, $this->entityListeners[$eventName] ?? [], true)) { |
956
|
5 |
|
return; |
957
|
|
|
} |
958
|
|
|
|
959
|
11 |
|
$this->entityListeners[$eventName][] = $listener; |
960
|
11 |
|
} |
961
|
|
|
|
962
|
|
|
/** |
963
|
|
|
* Sets the discriminator column definition. |
964
|
|
|
* |
965
|
|
|
* @see getDiscriminatorColumn() |
966
|
|
|
* |
967
|
|
|
* @throws MappingException |
968
|
|
|
*/ |
969
|
95 |
|
public function setDiscriminatorColumn(DiscriminatorColumnMetadata $discriminatorColumn) : void |
970
|
|
|
{ |
971
|
95 |
|
if (isset($this->fieldNames[$discriminatorColumn->getColumnName()])) { |
972
|
|
|
throw MappingException::duplicateColumnName($this->className, $discriminatorColumn->getColumnName()); |
973
|
|
|
} |
974
|
|
|
|
975
|
95 |
|
$discriminatorColumn->setTableName($discriminatorColumn->getTableName() ?? $this->getTableName()); |
976
|
|
|
|
977
|
95 |
|
$allowedTypeList = ['boolean', 'array', 'object', 'datetime', 'time', 'date']; |
978
|
|
|
|
979
|
95 |
|
if (in_array($discriminatorColumn->getTypeName(), $allowedTypeList, true)) { |
980
|
|
|
throw MappingException::invalidDiscriminatorColumnType($discriminatorColumn->getTypeName()); |
981
|
|
|
} |
982
|
|
|
|
983
|
95 |
|
$this->discriminatorColumn = $discriminatorColumn; |
984
|
95 |
|
} |
985
|
|
|
|
986
|
|
|
/** |
987
|
|
|
* Sets the discriminator values used by this class. |
988
|
|
|
* Used for JOINED and SINGLE_TABLE inheritance mapping strategies. |
989
|
|
|
* |
990
|
|
|
* @param string[] $map |
991
|
|
|
* |
992
|
|
|
* @throws MappingException |
993
|
|
|
*/ |
994
|
90 |
|
public function setDiscriminatorMap(array $map) : void |
995
|
|
|
{ |
996
|
90 |
|
foreach ($map as $value => $className) { |
997
|
90 |
|
$this->addDiscriminatorMapClass($value, $className); |
998
|
|
|
} |
999
|
90 |
|
} |
1000
|
|
|
|
1001
|
|
|
/** |
1002
|
|
|
* Adds one entry of the discriminator map with a new class and corresponding name. |
1003
|
|
|
* |
1004
|
|
|
* @param string|int $name |
1005
|
|
|
* |
1006
|
|
|
* @throws MappingException |
1007
|
|
|
*/ |
1008
|
90 |
|
public function addDiscriminatorMapClass($name, string $className) : void |
1009
|
|
|
{ |
1010
|
90 |
|
$this->discriminatorMap[$name] = $className; |
1011
|
|
|
|
1012
|
90 |
|
if ($this->className === $className) { |
1013
|
76 |
|
$this->discriminatorValue = $name; |
1014
|
|
|
|
1015
|
76 |
|
return; |
1016
|
|
|
} |
1017
|
|
|
|
1018
|
89 |
|
if (! (class_exists($className) || interface_exists($className))) { |
1019
|
|
|
throw MappingException::invalidClassInDiscriminatorMap($className, $this->className); |
1020
|
|
|
} |
1021
|
|
|
|
1022
|
89 |
|
if (is_subclass_of($className, $this->className) && ! in_array($className, $this->subClasses, true)) { |
1023
|
84 |
|
$this->subClasses[] = $className; |
1024
|
|
|
} |
1025
|
89 |
|
} |
1026
|
|
|
|
1027
|
1031 |
|
public function getValueGenerationPlan() : ValueGenerationPlan |
1028
|
|
|
{ |
1029
|
1031 |
|
return $this->valueGenerationPlan; |
1030
|
|
|
} |
1031
|
|
|
|
1032
|
368 |
|
public function setValueGenerationPlan(ValueGenerationPlan $valueGenerationPlan) : void |
1033
|
|
|
{ |
1034
|
368 |
|
$this->valueGenerationPlan = $valueGenerationPlan; |
1035
|
368 |
|
} |
1036
|
|
|
|
1037
|
399 |
|
public function checkPropertyDuplication(string $columnName) : bool |
1038
|
|
|
{ |
1039
|
399 |
|
return isset($this->fieldNames[$columnName]) |
1040
|
399 |
|
|| ($this->discriminatorColumn !== null && $this->discriminatorColumn->getColumnName() === $columnName); |
1041
|
|
|
} |
1042
|
|
|
|
1043
|
|
|
/** |
1044
|
|
|
* Marks this class as read only, no change tracking is applied to it. |
1045
|
|
|
*/ |
1046
|
2 |
|
public function asReadOnly() : void |
1047
|
|
|
{ |
1048
|
2 |
|
$this->readOnly = true; |
1049
|
2 |
|
} |
1050
|
|
|
|
1051
|
|
|
/** |
1052
|
|
|
* Whether this class is read only or not. |
1053
|
|
|
*/ |
1054
|
447 |
|
public function isReadOnly() : bool |
1055
|
|
|
{ |
1056
|
447 |
|
return $this->readOnly; |
1057
|
|
|
} |
1058
|
|
|
|
1059
|
1091 |
|
public function isVersioned() : bool |
1060
|
|
|
{ |
1061
|
1091 |
|
return $this->versionProperty !== null; |
1062
|
|
|
} |
1063
|
|
|
|
1064
|
|
|
/** |
1065
|
|
|
* Map Embedded Class |
1066
|
|
|
* |
1067
|
|
|
* @param mixed[] $mapping |
1068
|
|
|
* |
1069
|
|
|
* @throws MappingException |
1070
|
|
|
*/ |
1071
|
|
|
public function mapEmbedded(array $mapping) : void |
|
|
|
|
1072
|
|
|
{ |
1073
|
|
|
/*if (isset($this->properties[$mapping['fieldName']])) { |
1074
|
|
|
throw MappingException::duplicateProperty($this->className, $this->getProperty($mapping['fieldName'])); |
1075
|
|
|
} |
1076
|
|
|
|
1077
|
|
|
$this->embeddedClasses[$mapping['fieldName']] = [ |
1078
|
|
|
'class' => $this->fullyQualifiedClassName($mapping['class']), |
1079
|
|
|
'columnPrefix' => $mapping['columnPrefix'], |
1080
|
|
|
'declaredField' => $mapping['declaredField'] ?? null, |
1081
|
|
|
'originalField' => $mapping['originalField'] ?? null, |
1082
|
|
|
'declaringClass' => $this, |
1083
|
|
|
];*/ |
1084
|
|
|
} |
1085
|
|
|
|
1086
|
|
|
/** |
1087
|
|
|
* Inline the embeddable class |
1088
|
|
|
* |
1089
|
|
|
* @param string $property |
1090
|
|
|
*/ |
1091
|
|
|
public function inlineEmbeddable($property, ClassMetadata $embeddable) : void |
|
|
|
|
1092
|
|
|
{ |
1093
|
|
|
/*foreach ($embeddable->fieldMappings as $fieldName => $fieldMapping) { |
1094
|
|
|
$fieldMapping['fieldName'] = $property . "." . $fieldName; |
1095
|
|
|
$fieldMapping['originalClass'] = $fieldMapping['originalClass'] ?? $embeddable->getClassName(); |
1096
|
|
|
$fieldMapping['originalField'] = $fieldMapping['originalField'] ?? $fieldName; |
1097
|
|
|
$fieldMapping['declaredField'] = isset($fieldMapping['declaredField']) |
1098
|
|
|
? $property . '.' . $fieldMapping['declaredField'] |
1099
|
|
|
: $property; |
1100
|
|
|
|
1101
|
|
|
if (! empty($this->embeddedClasses[$property]['columnPrefix'])) { |
1102
|
|
|
$fieldMapping['columnName'] = $this->embeddedClasses[$property]['columnPrefix'] . $fieldMapping['columnName']; |
1103
|
|
|
} elseif ($this->embeddedClasses[$property]['columnPrefix'] !== false) { |
1104
|
|
|
$fieldMapping['columnName'] = $this->namingStrategy->embeddedFieldToColumnName( |
1105
|
|
|
$property, |
1106
|
|
|
$fieldMapping['columnName'], |
1107
|
|
|
$this->reflectionClass->getName(), |
1108
|
|
|
$embeddable->reflectionClass->getName() |
1109
|
|
|
); |
1110
|
|
|
} |
1111
|
|
|
|
1112
|
|
|
$this->mapField($fieldMapping); |
1113
|
|
|
}*/ |
1114
|
|
|
} |
1115
|
|
|
} |
1116
|
|
|
|