本文整理汇总了PHP中Doctrine\ODM\MongoDB\Mapping\ClassMetadata::getIdentifierValue方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::getIdentifierValue方法的具体用法?PHP ClassMetadata::getIdentifierValue怎么用?PHP ClassMetadata::getIdentifierValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ODM\MongoDB\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::getIdentifierValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getId
/** {@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;
}
示例2: scheduleForUpsert
/**
* 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);
}