diff options
Diffstat (limited to 'vendor/doctrine/orm/src/Id/AssignedGenerator.php')
-rw-r--r-- | vendor/doctrine/orm/src/Id/AssignedGenerator.php | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/vendor/doctrine/orm/src/Id/AssignedGenerator.php b/vendor/doctrine/orm/src/Id/AssignedGenerator.php new file mode 100644 index 0000000..e11b341 --- /dev/null +++ b/vendor/doctrine/orm/src/Id/AssignedGenerator.php | |||
@@ -0,0 +1,45 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Doctrine\ORM\Id; | ||
6 | |||
7 | use Doctrine\ORM\EntityManagerInterface; | ||
8 | use Doctrine\ORM\Exception\EntityMissingAssignedId; | ||
9 | |||
10 | /** | ||
11 | * Special generator for application-assigned identifiers (doesn't really generate anything). | ||
12 | */ | ||
13 | class AssignedGenerator extends AbstractIdGenerator | ||
14 | { | ||
15 | /** | ||
16 | * Returns the identifier assigned to the given entity. | ||
17 | * | ||
18 | * {@inheritDoc} | ||
19 | * | ||
20 | * @throws EntityMissingAssignedId | ||
21 | */ | ||
22 | public function generateId(EntityManagerInterface $em, object|null $entity): array | ||
23 | { | ||
24 | $class = $em->getClassMetadata($entity::class); | ||
25 | $idFields = $class->getIdentifierFieldNames(); | ||
26 | $identifier = []; | ||
27 | |||
28 | foreach ($idFields as $idField) { | ||
29 | $value = $class->getFieldValue($entity, $idField); | ||
30 | |||
31 | if (! isset($value)) { | ||
32 | throw EntityMissingAssignedId::forField($entity, $idField); | ||
33 | } | ||
34 | |||
35 | if (isset($class->associationMappings[$idField])) { | ||
36 | // NOTE: Single Columns as associated identifiers only allowed - this constraint it is enforced. | ||
37 | $value = $em->getUnitOfWork()->getSingleIdentifierValue($value); | ||
38 | } | ||
39 | |||
40 | $identifier[$idField] = $value; | ||
41 | } | ||
42 | |||
43 | return $identifier; | ||
44 | } | ||
45 | } | ||