1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\ORM\Mapping; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\EventManager; |
8
|
|
|
use Doctrine\DBAL\Platforms; |
9
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform; |
10
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
11
|
|
|
use Doctrine\ORM\Event\LoadClassMetadataEventArgs; |
12
|
|
|
use Doctrine\ORM\Event\OnClassMetadataNotFoundEventArgs; |
13
|
|
|
use Doctrine\ORM\Events; |
14
|
|
|
use Doctrine\ORM\ORMException; |
15
|
|
|
use Doctrine\ORM\Sequencing; |
16
|
|
|
use Doctrine\ORM\Sequencing\Planning\AssociationValueGeneratorExecutor; |
17
|
|
|
use Doctrine\ORM\Sequencing\Planning\ColumnValueGeneratorExecutor; |
18
|
|
|
use Doctrine\ORM\Sequencing\Planning\CompositeValueGenerationPlan; |
19
|
|
|
use Doctrine\ORM\Sequencing\Planning\NoopValueGenerationPlan; |
20
|
|
|
use Doctrine\ORM\Sequencing\Planning\SingleValueGenerationPlan; |
21
|
|
|
use Doctrine\ORM\Sequencing\Planning\ValueGenerationExecutor; |
22
|
|
|
use ReflectionException; |
23
|
|
|
use function array_map; |
24
|
|
|
use function class_exists; |
25
|
|
|
use function count; |
26
|
|
|
use function end; |
27
|
|
|
use function explode; |
28
|
|
|
use function is_subclass_of; |
29
|
|
|
use function sprintf; |
30
|
|
|
use function strpos; |
31
|
|
|
use function strtolower; |
32
|
|
|
use function var_export; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The ClassMetadataFactory is used to create ClassMetadata objects that contain all the |
36
|
|
|
* metadata mapping information of a class which describes how a class should be mapped |
37
|
|
|
* to a relational database. |
38
|
|
|
*/ |
39
|
|
|
class ClassMetadataFactory extends AbstractClassMetadataFactory |
40
|
|
|
{ |
41
|
|
|
/** |
42
|
|
|
* @var EntityManagerInterface|null |
43
|
|
|
*/ |
44
|
|
|
private $em; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var AbstractPlatform |
48
|
|
|
*/ |
49
|
|
|
private $targetPlatform; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var Driver\MappingDriver |
53
|
|
|
*/ |
54
|
|
|
private $driver; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var EventManager |
58
|
|
|
*/ |
59
|
|
|
private $evm; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
376 |
|
*/ |
64
|
|
|
protected function loadMetadata(string $name, ClassMetadataBuildingContext $metadataBuildingContext) : array |
65
|
376 |
|
{ |
66
|
|
|
$loaded = parent::loadMetadata($name, $metadataBuildingContext); |
67
|
357 |
|
|
68
|
|
|
array_map([$this, 'resolveDiscriminatorValue'], $loaded); |
69
|
357 |
|
|
70
|
|
|
return $loaded; |
71
|
|
|
} |
72
|
2247 |
|
|
73
|
|
|
public function setEntityManager(EntityManagerInterface $em) |
74
|
2247 |
|
{ |
75
|
2247 |
|
$this->em = $em; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* {@inheritdoc} |
80
|
|
|
* |
81
|
|
|
* @throws ORMException |
82
|
442 |
|
*/ |
83
|
|
|
protected function initialize() : void |
84
|
442 |
|
{ |
85
|
442 |
|
$this->driver = $this->em->getConfiguration()->getMetadataDriverImpl(); |
|
|
|
|
86
|
442 |
|
$this->evm = $this->em->getEventManager(); |
87
|
442 |
|
$this->initialized = true; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* {@inheritdoc} |
92
|
12 |
|
*/ |
93
|
|
|
protected function onNotFoundMetadata( |
94
|
|
|
string $className, |
95
|
|
|
ClassMetadataBuildingContext $metadataBuildingContext |
96
|
12 |
|
) : ?ClassMetadata { |
97
|
10 |
|
if (! $this->evm->hasListeners(Events::onClassMetadataNotFound)) { |
98
|
|
|
return null; |
99
|
|
|
} |
100
|
2 |
|
|
101
|
|
|
$eventArgs = new OnClassMetadataNotFoundEventArgs($className, $metadataBuildingContext, $this->em); |
|
|
|
|
102
|
2 |
|
|
103
|
|
|
$this->evm->dispatchEvent(Events::onClassMetadataNotFound, $eventArgs); |
104
|
2 |
|
|
105
|
|
|
return $eventArgs->getFoundMetadata(); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* {@inheritdoc} |
110
|
|
|
* |
111
|
|
|
* @throws MappingException |
112
|
|
|
* @throws ORMException |
113
|
364 |
|
*/ |
114
|
|
|
protected function doLoadMetadata( |
115
|
|
|
string $className, |
116
|
|
|
?ClassMetadata $parent, |
117
|
|
|
ClassMetadataBuildingContext $metadataBuildingContext |
118
|
364 |
|
) : ClassMetadata { |
119
|
|
|
$classMetadata = new ClassMetadata($className, $metadataBuildingContext); |
120
|
364 |
|
|
121
|
98 |
|
if ($parent) { |
122
|
|
|
$classMetadata->setParent($parent); |
123
|
98 |
|
|
124
|
97 |
|
foreach ($parent->getDeclaredPropertiesIterator() as $fieldName => $property) { |
125
|
|
|
$classMetadata->addInheritedProperty($property); |
126
|
|
|
} |
127
|
98 |
|
|
128
|
98 |
|
$classMetadata->setInheritanceType($parent->inheritanceType); |
|
|
|
|
129
|
|
|
$classMetadata->setIdentifier($parent->identifier); |
130
|
98 |
|
|
131
|
72 |
|
if ($parent->discriminatorColumn) { |
132
|
72 |
|
$classMetadata->setDiscriminatorColumn($parent->discriminatorColumn); |
133
|
|
|
$classMetadata->setDiscriminatorMap($parent->discriminatorMap); |
134
|
|
|
} |
135
|
98 |
|
|
136
|
98 |
|
$classMetadata->setLifecycleCallbacks($parent->lifecycleCallbacks); |
137
|
|
|
$classMetadata->setChangeTrackingPolicy($parent->changeTrackingPolicy); |
138
|
98 |
|
|
139
|
28 |
|
if ($parent->isMappedSuperclass) { |
140
|
|
|
$classMetadata->setCustomRepositoryClassName($parent->getCustomRepositoryClassName()); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
// Invoke driver |
145
|
364 |
|
try { |
146
|
3 |
|
$this->driver->loadMetadataForClass($classMetadata->getClassName(), $classMetadata, $metadataBuildingContext); |
147
|
|
|
} catch (ReflectionException $e) { |
148
|
|
|
throw MappingException::reflectionFailure($classMetadata->getClassName(), $e); |
149
|
|
|
} |
150
|
361 |
|
|
151
|
|
|
$this->completeIdentifierGeneratorMappings($classMetadata); |
152
|
361 |
|
|
153
|
98 |
|
if ($parent) { |
154
|
3 |
|
if ($parent->getCache()) { |
155
|
|
|
$classMetadata->setCache(clone $parent->getCache()); |
156
|
|
|
} |
157
|
98 |
|
|
158
|
7 |
|
if (! empty($parent->entityListeners) && empty($classMetadata->entityListeners)) { |
159
|
|
|
$classMetadata->entityListeners = $parent->entityListeners; |
160
|
|
|
} |
161
|
|
|
} |
162
|
361 |
|
|
163
|
1 |
|
if (! $classMetadata->discriminatorMap && $classMetadata->inheritanceType !== InheritanceType::NONE && $classMetadata->isRootEntity()) { |
|
|
|
|
164
|
|
|
$this->addDefaultDiscriminatorMap($classMetadata); |
165
|
|
|
} |
166
|
361 |
|
|
167
|
|
|
$this->completeRuntimeMetadata($classMetadata, $parent); |
168
|
361 |
|
|
169
|
6 |
|
if ($this->evm->hasListeners(Events::loadClassMetadata)) { |
170
|
|
|
$eventArgs = new LoadClassMetadataEventArgs($classMetadata, $this->em); |
|
|
|
|
171
|
6 |
|
|
172
|
|
|
$this->evm->dispatchEvent(Events::loadClassMetadata, $eventArgs); |
173
|
|
|
} |
174
|
360 |
|
|
175
|
360 |
|
$this->buildValueGenerationPlan($classMetadata); |
176
|
|
|
$this->validateRuntimeMetadata($classMetadata, $parent); |
177
|
358 |
|
|
178
|
|
|
return $classMetadata; |
179
|
|
|
} |
180
|
361 |
|
|
181
|
|
|
protected function completeRuntimeMetadata(ClassMetadata $class, ?ClassMetadata $parent = null) : void |
182
|
361 |
|
{ |
183
|
361 |
|
if (! $parent || ! $parent->isMappedSuperclass) { |
184
|
|
|
return; |
185
|
|
|
} |
186
|
28 |
|
|
187
|
1 |
|
if ($class->isMappedSuperclass) { |
188
|
|
|
return; |
189
|
|
|
} |
190
|
28 |
|
|
191
|
|
|
$tableName = $class->getTableName(); |
192
|
|
|
|
193
|
28 |
|
// Resolve column table names |
194
|
28 |
|
foreach ($class->getDeclaredPropertiesIterator() as $property) { |
195
|
28 |
|
if ($property instanceof FieldMetadata) { |
196
|
|
|
$property->setTableName($property->getTableName() ?? $tableName); |
197
|
28 |
|
|
198
|
|
|
continue; |
199
|
|
|
} |
200
|
12 |
|
|
201
|
12 |
|
if (! ($property instanceof ToOneAssociationMetadata)) { |
202
|
|
|
continue; |
203
|
|
|
} |
204
|
|
|
|
205
|
9 |
|
// Resolve association join column table names |
206
|
|
|
foreach ($property->getJoinColumns() as $joinColumn) { |
207
|
9 |
|
/** @var JoinColumnMetadata $joinColumn */ |
208
|
|
|
$joinColumn->setTableName($joinColumn->getTableName() ?? $tableName); |
209
|
|
|
} |
210
|
28 |
|
} |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Validate runtime metadata is correctly defined. |
215
|
|
|
* |
216
|
|
|
* @throws MappingException |
217
|
360 |
|
*/ |
218
|
|
|
protected function validateRuntimeMetadata(ClassMetadata $class, ?ClassMetadata $parent = null) : void |
219
|
360 |
|
{ |
220
|
|
|
if (! $class->getReflectionClass()) { |
221
|
|
|
// only validate if there is a reflection class instance |
222
|
|
|
return; |
223
|
|
|
} |
224
|
360 |
|
|
225
|
358 |
|
$class->validateIdentifier(); |
226
|
358 |
|
$class->validateAssociations(); |
227
|
|
|
$class->validateLifecycleCallbacks($this->getReflectionService()); |
228
|
|
|
|
229
|
358 |
|
// verify inheritance |
230
|
75 |
|
if (! $class->isMappedSuperclass && $class->inheritanceType !== InheritanceType::NONE) { |
231
|
74 |
|
if (! $parent) { |
232
|
|
|
if (! $class->discriminatorMap) { |
|
|
|
|
233
|
|
|
throw MappingException::missingDiscriminatorMap($class->getClassName()); |
234
|
|
|
} |
235
|
74 |
|
|
236
|
75 |
|
if (! $class->discriminatorColumn) { |
237
|
|
|
throw MappingException::missingDiscriminatorColumn($class->getClassName()); |
238
|
|
|
} |
239
|
322 |
|
} |
240
|
|
|
} elseif (($class->discriminatorMap || $class->discriminatorColumn) && $class->isMappedSuperclass && $class->isRootEntity()) { |
|
|
|
|
241
|
|
|
// second condition is necessary for mapped superclasses in the middle of an inheritance hierarchy |
242
|
|
|
throw MappingException::noInheritanceOnMappedSuperClass($class->getClassName()); |
243
|
358 |
|
} |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* {@inheritdoc} |
248
|
1946 |
|
*/ |
249
|
|
|
protected function newClassMetadataBuildingContext() : ClassMetadataBuildingContext |
250
|
1946 |
|
{ |
251
|
1946 |
|
return new ClassMetadataBuildingContext( |
252
|
1946 |
|
$this, |
253
|
1946 |
|
$this->getReflectionService(), |
254
|
|
|
$this->em->getConfiguration()->getNamingStrategy() |
255
|
|
|
); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* Populates the discriminator value of the given metadata (if not set) by iterating over discriminator |
260
|
|
|
* map classes and looking for a fitting one. |
261
|
|
|
* |
262
|
|
|
* @throws \InvalidArgumentException |
263
|
|
|
* @throws \ReflectionException |
264
|
|
|
* @throws MappingException |
265
|
357 |
|
*/ |
266
|
|
|
private function resolveDiscriminatorValue(ClassMetadata $metadata) : void |
267
|
357 |
|
{ |
268
|
357 |
|
if ($metadata->discriminatorValue || ! $metadata->discriminatorMap || $metadata->isMappedSuperclass || |
|
|
|
|
269
|
357 |
|
! $metadata->getReflectionClass() || $metadata->getReflectionClass()->isAbstract()) { |
270
|
|
|
return; |
271
|
|
|
} |
272
|
|
|
|
273
|
4 |
|
// minor optimization: avoid loading related metadata when not needed |
274
|
4 |
|
foreach ($metadata->discriminatorMap as $discriminatorValue => $discriminatorClass) { |
275
|
3 |
|
if ($discriminatorClass === $metadata->getClassName()) { |
276
|
|
|
$metadata->discriminatorValue = $discriminatorValue; |
277
|
4 |
|
|
278
|
|
|
return; |
279
|
|
|
} |
280
|
|
|
} |
281
|
|
|
|
282
|
1 |
|
// iterate over discriminator mappings and resolve actual referenced classes according to existing metadata |
283
|
1 |
|
foreach ($metadata->discriminatorMap as $discriminatorValue => $discriminatorClass) { |
284
|
|
|
if ($metadata->getClassName() === $this->getMetadataFor($discriminatorClass)->getClassName()) { |
285
|
|
|
$metadata->discriminatorValue = $discriminatorValue; |
286
|
1 |
|
|
287
|
|
|
return; |
288
|
|
|
} |
289
|
|
|
} |
290
|
1 |
|
|
291
|
|
|
throw MappingException::mappedClassNotPartOfDiscriminatorMap($metadata->getClassName(), $metadata->getRootClassName()); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* Adds a default discriminator map if no one is given |
296
|
|
|
* |
297
|
|
|
* If an entity is of any inheritance type and does not contain a |
298
|
|
|
* discriminator map, then the map is generated automatically. This process |
299
|
|
|
* is expensive computation wise. |
300
|
|
|
* |
301
|
|
|
* The automatically generated discriminator map contains the lowercase short name of |
302
|
|
|
* each class as key. |
303
|
|
|
* |
304
|
|
|
* @throws MappingException |
305
|
1 |
|
*/ |
306
|
|
|
private function addDefaultDiscriminatorMap(ClassMetadata $class) : void |
307
|
1 |
|
{ |
308
|
1 |
|
$allClasses = $this->driver->getAllClassNames(); |
309
|
1 |
|
$fqcn = $class->getClassName(); |
310
|
1 |
|
$map = [$this->getShortName($fqcn) => $fqcn]; |
311
|
|
|
$duplicates = []; |
312
|
1 |
|
|
313
|
1 |
|
foreach ($allClasses as $subClassCandidate) { |
314
|
1 |
|
if (is_subclass_of($subClassCandidate, $fqcn)) { |
315
|
|
|
$shortName = $this->getShortName($subClassCandidate); |
316
|
1 |
|
|
317
|
|
|
if (isset($map[$shortName])) { |
318
|
|
|
$duplicates[] = $shortName; |
319
|
|
|
} |
320
|
1 |
|
|
321
|
|
|
$map[$shortName] = $subClassCandidate; |
322
|
|
|
} |
323
|
|
|
} |
324
|
1 |
|
|
325
|
|
|
if ($duplicates) { |
326
|
|
|
throw MappingException::duplicateDiscriminatorEntry($class->getClassName(), $duplicates, $map); |
327
|
|
|
} |
328
|
1 |
|
|
329
|
1 |
|
$class->setDiscriminatorMap($map); |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* Gets the lower-case short name of a class. |
334
|
|
|
* |
335
|
|
|
* @param string $className |
336
|
1 |
|
*/ |
337
|
|
|
private function getShortName($className) : string |
338
|
1 |
|
{ |
339
|
|
|
if (strpos($className, '\\') === false) { |
340
|
|
|
return strtolower($className); |
341
|
|
|
} |
342
|
1 |
|
|
343
|
|
|
$parts = explode('\\', $className); |
344
|
1 |
|
|
345
|
|
|
return strtolower(end($parts)); |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* Completes the ID generator mapping. If "auto" is specified we choose the generator |
350
|
|
|
* most appropriate for the targeted database platform. |
351
|
|
|
* |
352
|
|
|
* @throws ORMException |
353
|
361 |
|
*/ |
354
|
|
|
private function completeIdentifierGeneratorMappings(ClassMetadata $class) : void |
355
|
361 |
|
{ |
356
|
359 |
|
foreach ($class->getDeclaredPropertiesIterator() as $property) { |
357
|
248 |
|
if (! $property instanceof FieldMetadata /*&& ! $property instanceof AssocationMetadata*/) { |
|
|
|
|
358
|
|
|
continue; |
359
|
|
|
} |
360
|
357 |
|
|
361
|
|
|
$this->completeFieldIdentifierGeneratorMapping($property); |
362
|
361 |
|
} |
363
|
|
|
} |
364
|
357 |
|
|
365
|
|
|
private function completeFieldIdentifierGeneratorMapping(FieldMetadata $field) |
366
|
357 |
|
{ |
367
|
277 |
|
if (! $field->hasValueGenerator()) { |
368
|
|
|
return; |
369
|
|
|
} |
370
|
287 |
|
|
371
|
287 |
|
$platform = $this->getTargetPlatform(); |
372
|
287 |
|
$class = $field->getDeclaringClass(); |
|
|
|
|
373
|
|
|
$generator = $field->getValueGenerator(); |
374
|
287 |
|
|
375
|
277 |
|
if ($generator->getType() === GeneratorType::AUTO) { |
376
|
277 |
|
$generator = new ValueGeneratorMetadata( |
377
|
|
|
$platform->prefersSequences() |
378
|
277 |
|
? GeneratorType::SEQUENCE |
379
|
277 |
|
: ($platform->prefersIdentityColumns() |
380
|
277 |
|
? GeneratorType::IDENTITY |
381
|
|
|
: GeneratorType::TABLE |
382
|
277 |
|
), |
383
|
|
|
$field->getValueGenerator()->getDefinition() |
384
|
277 |
|
); |
385
|
|
|
$field->setValueGenerator($generator); |
386
|
|
|
} |
387
|
|
|
|
388
|
287 |
|
// Validate generator definition and set defaults where needed |
389
|
287 |
|
switch ($generator->getType()) { |
390
|
|
|
case GeneratorType::SEQUENCE: |
391
|
6 |
|
// If there is no sequence definition yet, create a default definition |
392
|
6 |
|
if ($generator->getDefinition()) { |
393
|
|
|
break; |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
// @todo guilhermeblanco Move sequence generation to DBAL |
397
|
|
|
$sequencePrefix = $platform->getSequencePrefix($field->getTableName(), $field->getSchemaName()); |
|
|
|
|
398
|
|
|
$idSequenceName = sprintf('%s_%s_seq', $sequencePrefix, $field->getColumnName()); |
399
|
|
|
$sequenceName = $platform->fixSchemaElementName($idSequenceName); |
400
|
|
|
|
401
|
|
|
$field->setValueGenerator( |
402
|
|
|
new ValueGeneratorMetadata( |
403
|
|
|
$generator->getType(), |
404
|
|
|
[ |
405
|
|
|
'sequenceName' => $sequenceName, |
406
|
|
|
'allocationSize' => 1, |
407
|
|
|
] |
408
|
|
|
) |
409
|
|
|
); |
410
|
|
|
|
411
|
|
|
break; |
412
|
281 |
|
|
413
|
|
|
case GeneratorType::TABLE: |
414
|
|
|
throw new ORMException('TableGenerator not yet implemented.'); |
415
|
|
|
break; |
416
|
281 |
|
|
417
|
1 |
|
case GeneratorType::CUSTOM: |
418
|
1 |
|
$definition = $generator->getDefinition(); |
419
|
|
|
if (! isset($definition['class'])) { |
420
|
|
|
throw new ORMException(sprintf('Cannot instantiate custom generator, no class has been defined')); |
421
|
1 |
|
} |
422
|
|
|
if (! class_exists($definition['class'])) { |
423
|
|
|
throw new ORMException(sprintf('Cannot instantiate custom generator : %s', var_export($definition, true))); //$definition['class'])); |
|
|
|
|
424
|
|
|
} |
425
|
1 |
|
|
426
|
|
|
break; |
427
|
280 |
|
|
428
|
|
|
case GeneratorType::IDENTITY: |
429
|
|
|
case GeneratorType::NONE: |
430
|
280 |
|
case GeneratorType::UUID: |
431
|
|
|
break; |
432
|
|
|
|
433
|
|
|
default: |
434
|
|
|
throw new ORMException('Unknown generator type: ' . $generator->getType()); |
435
|
287 |
|
} |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
/** |
439
|
|
|
* {@inheritDoc} |
440
|
198 |
|
*/ |
441
|
|
|
protected function getDriver() : Driver\MappingDriver |
442
|
198 |
|
{ |
443
|
|
|
return $this->driver; |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
/** |
447
|
|
|
* {@inheritDoc} |
448
|
|
|
*/ |
449
|
|
|
protected function isEntity(ClassMetadata $class) : bool |
450
|
|
|
{ |
451
|
|
|
return isset($class->isMappedSuperclass) && $class->isMappedSuperclass === false; |
452
|
|
|
} |
453
|
287 |
|
|
454
|
|
|
private function getTargetPlatform() : Platforms\AbstractPlatform |
455
|
287 |
|
{ |
456
|
287 |
|
if (! $this->targetPlatform) { |
457
|
|
|
$this->targetPlatform = $this->em->getConnection()->getDatabasePlatform(); |
458
|
|
|
} |
459
|
287 |
|
|
460
|
|
|
return $this->targetPlatform; |
461
|
|
|
} |
462
|
360 |
|
|
463
|
|
|
private function buildValueGenerationPlan(ClassMetadata $class) : void |
464
|
|
|
{ |
465
|
360 |
|
$executors = $this->buildValueGenerationExecutorList($class); |
466
|
|
|
|
467
|
360 |
|
switch (count($executors)) { |
468
|
358 |
|
case 0: |
469
|
328 |
|
$class->setValueGenerationPlan(new NoopValueGenerationPlan()); |
470
|
|
|
break; |
471
|
|
|
|
472
|
286 |
|
case 1: |
473
|
|
|
$class->setValueGenerationPlan(new SingleValueGenerationPlan($class, $executors[0])); |
474
|
|
|
break; |
475
|
360 |
|
|
476
|
360 |
|
default: |
477
|
113 |
|
$class->setValueGenerationPlan(new CompositeValueGenerationPlan($class, $executors)); |
478
|
113 |
|
break; |
479
|
|
|
} |
480
|
286 |
|
} |
481
|
286 |
|
|
482
|
286 |
|
/** |
483
|
|
|
* @return ValueGenerationExecutor[] |
484
|
286 |
|
*/ |
485
|
286 |
|
private function buildValueGenerationExecutorList(ClassMetadata $class) : array |
486
|
|
|
{ |
487
|
|
|
$executors = []; |
488
|
|
|
|
489
|
|
|
foreach ($class->getDeclaredPropertiesIterator() as $property) { |
490
|
|
|
$executor = $this->buildValueGenerationExecutorForProperty($class, $property); |
491
|
|
|
|
492
|
|
|
if ($executor instanceof ValueGenerationExecutor) { |
493
|
|
|
$executors[] = $executor; |
494
|
|
|
} |
495
|
|
|
} |
496
|
|
|
|
497
|
360 |
|
return $executors; |
498
|
|
|
} |
499
|
286 |
|
|
500
|
|
|
private function buildValueGenerationExecutorForProperty( |
501
|
|
|
ClassMetadata $class, |
502
|
|
|
Property $property |
503
|
286 |
|
) : ?ValueGenerationExecutor { |
504
|
|
|
if ($property instanceof LocalColumnMetadata && $property->hasValueGenerator()) { |
505
|
286 |
|
return new ColumnValueGeneratorExecutor($property, $this->createPropertyValueGenerator($class, $property)); |
506
|
286 |
|
} |
507
|
279 |
|
|
508
|
|
|
if ($property instanceof ToOneAssociationMetadata && $property->isPrimaryKey()) { |
509
|
|
|
return new AssociationValueGeneratorExecutor(); |
510
|
279 |
|
} |
511
|
|
|
|
512
|
|
|
return null; |
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
private function createPropertyValueGenerator( |
516
|
279 |
|
ClassMetadata $class, |
517
|
1 |
|
LocalColumnMetadata $property |
518
|
279 |
|
) : Sequencing\Generator { |
519
|
|
|
$platform = $this->getTargetPlatform(); |
520
|
7 |
|
|
521
|
6 |
|
switch ($property->getValueGenerator()->getType()) { |
522
|
6 |
|
case GeneratorType::IDENTITY: |
523
|
6 |
|
$sequenceName = null; |
524
|
6 |
|
|
525
|
|
|
// Platforms that do not have native IDENTITY support need a sequence to emulate this behaviour. |
526
|
|
|
if ($platform->usesSequenceEmulatedIdentityColumns()) { |
527
|
|
|
$sequencePrefix = $platform->getSequencePrefix($class->getTableName(), $class->getSchemaName()); |
528
|
1 |
|
$idSequenceName = $platform->getIdentitySequenceName($sequencePrefix, $property->getColumnName()); |
529
|
|
|
$sequenceName = $platform->quoteIdentifier($platform->fixSchemaElementName($idSequenceName)); |
530
|
|
|
} |
531
|
|
|
|
532
|
1 |
|
return $property->getTypeName() === 'bigint' |
533
|
1 |
|
? new Sequencing\BigIntegerIdentityGenerator($sequenceName) |
534
|
1 |
|
: new Sequencing\IdentityGenerator($sequenceName); |
535
|
|
|
|
536
|
|
|
case GeneratorType::SEQUENCE: |
537
|
|
|
$definition = $property->getValueGenerator()->getDefinition(); |
538
|
|
|
return new Sequencing\SequenceGenerator( |
539
|
|
|
$platform->quoteIdentifier($definition['sequenceName']), |
540
|
|
|
$definition['allocationSize'] |
541
|
|
|
); |
542
|
|
|
break; |
|
|
|
|
543
|
|
|
|
544
|
|
|
case GeneratorType::UUID: |
545
|
|
|
return new Sequencing\UuidGenerator(); |
546
|
|
|
break; |
547
|
|
|
|
548
|
|
|
case GeneratorType::CUSTOM: |
549
|
|
|
$class = $property->getValueGenerator()->getDefinition()['class']; |
550
|
|
|
return new $class(); |
551
|
|
|
break; |
552
|
|
|
} |
553
|
|
|
} |
554
|
|
|
} |
555
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.