123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
-
-
- namespace Doctrine\ORM\Id;
-
- use Doctrine\ORM\EntityManager;
- use Doctrine\ORM\ORMException;
-
-
- class AssignedGenerator extends AbstractIdGenerator
- {
-
-
- public function generate(EntityManager $em, $entity)
- {
- $class = $em->getClassMetadata(get_class($entity));
- $identifier = array();
- if ($class->isIdentifierComposite) {
- $idFields = $class->getIdentifierFieldNames();
- foreach ($idFields as $idField) {
- $value = $class->reflFields[$idField]->getValue($entity);
- if (isset($value)) {
- if (isset($class->associationMappings[$idField])) {
- if (!$em->getUnitOfWork()->isInIdentityMap($value)) {
- throw ORMException::entityMissingForeignAssignedId($entity, $value);
- }
-
-
- $identifier[$idField] = current($em->getUnitOfWork()->getEntityIdentifier($value));
- } else {
- $identifier[$idField] = $value;
- }
- } else {
- throw ORMException::entityMissingAssignedId($entity);
- }
- }
- } else {
- $idField = $class->identifier[0];
- $value = $class->reflFields[$idField]->getValue($entity);
- if (isset($value)) {
- if (isset($class->associationMappings[$idField])) {
- if (!$em->getUnitOfWork()->isInIdentityMap($value)) {
- throw ORMException::entityMissingForeignAssignedId($entity, $value);
- }
-
-
- $identifier[$idField] = current($em->getUnitOfWork()->getEntityIdentifier($value));
- } else {
- $identifier[$idField] = $value;
- }
- } else {
- throw ORMException::entityMissingAssignedId($entity);
- }
- }
-
- return $identifier;
- }
- }
|