本文整理汇总了PHP中Doctrine\ODM\MongoDB\UnitOfWork::getDocumentActualData方法的典型用法代码示例。如果您正苦于以下问题:PHP UnitOfWork::getDocumentActualData方法的具体用法?PHP UnitOfWork::getDocumentActualData怎么用?PHP UnitOfWork::getDocumentActualData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ODM\MongoDB\UnitOfWork
的用法示例。
在下文中一共展示了UnitOfWork::getDocumentActualData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getShardKeyQuery
/**
* @param object $document
*
* @return array
* @throws MongoDBException
*/
private function getShardKeyQuery($document)
{
if (!$this->class->isSharded()) {
return array();
}
$shardKey = $this->class->getShardKey();
$keys = array_keys($shardKey['keys']);
$data = $this->uow->getDocumentActualData($document);
$shardKeyQueryPart = array();
foreach ($keys as $key) {
$mapping = $this->class->getFieldMappingByDbFieldName($key);
$this->guardMissingShardKey($document, $key, $data);
$value = Type::getType($mapping['type'])->convertToDatabaseValue($data[$mapping['fieldName']]);
$shardKeyQueryPart[$key] = $value;
}
return $shardKeyQueryPart;
}
示例2: getShardKeyQuery
/**
* @param $document
* @return array
* @throws MongoDBException
*/
public function getShardKeyQuery($document)
{
$shardKeysQueryPart = array();
$dcs = $this->uow->getDocumentChangeSet($document);
$data = $this->uow->getDocumentActualData($document);
$md = $this->dm->getMetadataFactory()->getMetadataFor(get_class($document));
$keys = $md->shardKeys;
$fieldMappings = $this->dm->getClassMetadata(get_class($document))->fieldMappings;
foreach ($keys as $key) {
if ($key !== 'id') {
$queryKey = $fieldMappings[$key]['name'];
} else {
$queryKey = '_id';
}
//If the document is new, we can ignore shard key value, otherwise throw exception
$isUpdate = $this->uow->isScheduledForUpdate($document);
if ($isUpdate && isset($dcs[$key]) && $dcs[$key][0] !== null && $dcs[$key][0] != $dcs[$key][1] && (!isset($options['upsert']) || isset($options['upsert']) && $options['upsert'] === true)) {
throw MongoDBException::shardKeyChange($key);
}
if (!isset($data[$key])) {
throw MongoDBException::shardKeyMissing($key);
}
$new = $data[$key];
$mapping = $fieldMappings[$key];
// @Field, @String, @Date, etc.
if (!isset($mapping['association'])) {
if (isset($new) || $mapping['nullable'] === true) {
$shardKeysQueryPart[$queryKey] = is_null($new) ? null : Type::getType($mapping['type'])->convertToDatabaseValue($new);
}
// @ReferenceOne
} elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::REFERENCE_ONE && $mapping['isOwningSide']) {
if (isset($new) || $mapping['nullable'] === true) {
$shardKeysQueryPart[$queryKey] = is_null($new) ? null : $this->pb->prepareReferencedDocumentValue($mapping, $new);
}
// @ReferenceMany
} elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::REFERENCE_MANY) {
// Do nothing right now
}
}
return $shardKeysQueryPart;
}