. */ 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 Roman Borschel * @todo Rename: AssignedGenerator? */ class Assigned 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->getReflectionProperty($idField)->getValue($entity); if (isset($value)) { $identifier[$idField] = $value; } else { throw ORMException::entityMissingAssignedId($entity); } } } else { $idField = $class->identifier[0]; $value = $class->reflFields[$idField]->getValue($entity); if (isset($value)) { $identifier[$idField] = $value; } else { throw ORMException::entityMissingAssignedId($entity); } } return $identifier; } }