/** {@inheritdoc} */ public function getId($object) { if (!is_a($object, $this->getClass())) { throw new MetadataException("Object isn't subclass of '{$this->getClass()}', given '" . (is_object($object) ? get_class($object) : gettype($object)) . "'."); } if ($this->classMetadata->isEmbeddedDocument) { throw new MetadataException("Embedded document '{$this->getClass()}' hasn't ID."); } $identifier = $this->classMetadata->getIdentifierValue($object); return empty($identifier) ? NULL : $identifier; }
/** * Schedules a document for upsert into the database and adds it to the * identity map * * @param ClassMetadata $class * @param object $document The document to schedule for upsert. * @throws \InvalidArgumentException */ public function scheduleForUpsert(ClassMetadata $class, $document) { $oid = spl_object_hash($document); if ($class->isEmbeddedDocument) { throw new \InvalidArgumentException("Embedded document can not be scheduled for upsert."); } if (isset($this->documentUpdates[$oid])) { throw new \InvalidArgumentException("Dirty document can not be scheduled for upsert."); } if (isset($this->documentDeletions[$oid])) { throw new \InvalidArgumentException("Removed document can not be scheduled for upsert."); } if (isset($this->documentUpserts[$oid])) { throw new \InvalidArgumentException("Document can not be scheduled for upsert twice."); } $this->documentUpserts[$oid] = $document; $this->documentIdentifiers[$oid] = $class->getIdentifierValue($document); $this->addToIdentityMap($document); }