AbstractIdGenerator.php
9 months ago
AssignedGenerator.php
9 months ago
BigIntegerIdentityGenerator.php
9 months ago
IdentityGenerator.php
9 months ago
SequenceGenerator.php
9 months ago
TableGenerator.php
9 months ago
UuidGenerator.php
9 months ago
index.php
9 months ago
AssignedGenerator.php
29 lines
| 1 | <?php |
| 2 | declare (strict_types=1); |
| 3 | namespace MailPoetVendor\Doctrine\ORM\Id; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use MailPoetVendor\Doctrine\ORM\EntityManagerInterface; |
| 6 | use MailPoetVendor\Doctrine\ORM\Exception\EntityMissingAssignedId; |
| 7 | use function get_class; |
| 8 | class AssignedGenerator extends AbstractIdGenerator |
| 9 | { |
| 10 | public function generateId(EntityManagerInterface $em, $entity) |
| 11 | { |
| 12 | $class = $em->getClassMetadata(get_class($entity)); |
| 13 | $idFields = $class->getIdentifierFieldNames(); |
| 14 | $identifier = []; |
| 15 | foreach ($idFields as $idField) { |
| 16 | $value = $class->getFieldValue($entity, $idField); |
| 17 | if (!isset($value)) { |
| 18 | throw EntityMissingAssignedId::forField($entity, $idField); |
| 19 | } |
| 20 | if (isset($class->associationMappings[$idField])) { |
| 21 | // NOTE: Single Columns as associated identifiers only allowed - this constraint it is enforced. |
| 22 | $value = $em->getUnitOfWork()->getSingleIdentifierValue($value); |
| 23 | } |
| 24 | $identifier[$idField] = $value; |
| 25 | } |
| 26 | return $identifier; |
| 27 | } |
| 28 | } |
| 29 |