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