diff -r 000000000000 -r 7f95f8617b0b vendor/doctrine/lib/Doctrine/ORM/Id/AssignedGenerator.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/doctrine/lib/Doctrine/ORM/Id/AssignedGenerator.php Sat Sep 24 15:40:41 2011 +0200 @@ -0,0 +1,87 @@ +. + */ + +namespace Doctrine\ORM\Id; + +use Doctrine\ORM\EntityManager; +use Doctrine\ORM\ORMException; + +/** + * Special generator for application-assigned identifiers (doesnt really generate anything). + * + * @since 2.0 + * @author Benjamin Eberlei + * @author Guilherme Blanco + * @author Jonathan Wage + * @author Roman Borschel + */ +class AssignedGenerator extends AbstractIdGenerator +{ + /** + * Returns the identifier assigned to the given entity. + * + * @param object $entity + * @return mixed + * @override + */ + 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); + } + + // NOTE: Single Columns as associated identifiers only allowed - this constraint it is enforced. + $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); + } + + // NOTE: Single Columns as associated identifiers only allowed - this constraint it is enforced. + $identifier[$idField] = current($em->getUnitOfWork()->getEntityIdentifier($value)); + } else { + $identifier[$idField] = $value; + } + } else { + throw ORMException::entityMissingAssignedId($entity); + } + } + + return $identifier; + } +} \ No newline at end of file