本文整理汇总了PHP中Doctrine\ODM\MongoDB\UnitOfWork::scheduleExtraUpdate方法的典型用法代码示例。如果您正苦于以下问题:PHP UnitOfWork::scheduleExtraUpdate方法的具体用法?PHP UnitOfWork::scheduleExtraUpdate怎么用?PHP UnitOfWork::scheduleExtraUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ODM\MongoDB\UnitOfWork
的用法示例。
在下文中一共展示了UnitOfWork::scheduleExtraUpdate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepareInsertData
/**
* Prepares insert data for document
*
* @param mixed $document
* @return array
*/
public function prepareInsertData($document)
{
$oid = spl_object_hash($document);
$class = $this->dm->getClassMetadata(get_class($document));
$changeset = $this->uow->getDocumentChangeSet($document);
$insertData = array();
foreach ($class->fieldMappings as $mapping) {
// many collections are inserted later
if ($mapping['type'] === 'many') {
continue;
}
// skip not saved fields
if (isset($mapping['notSaved']) && $mapping['notSaved'] === true) {
continue;
}
// Skip version and lock fields
if (isset($mapping['version']) || isset($mapping['lock'])) {
continue;
}
$new = isset($changeset[$mapping['fieldName']][1]) ? $changeset[$mapping['fieldName']][1] : null;
// Prepare new document identifier
if ($class->isIdentifier($mapping['fieldName'])) {
if ( ! $class->isIdGeneratorNone() && $new === null) {
$new = $class->idGenerator->generate($this->dm, $document);
}
$insertData['_id'] = Type::getType($mapping['type'])->convertToDatabaseValue($new);
continue;
}
// Skip null values
if ($new === null && $mapping['nullable'] === false) {
continue;
}
$value = $this->prepareValue($mapping, $new);
// Check if a reference is not persisted yet and we need to schedule an extra update
$insertData[$mapping['name']] = $value;
if (isset($mapping['reference'])) {
$scheduleForUpdate = false;
if ($mapping['type'] === 'one') {
if ( ! isset($insertData[$mapping['name']][$this->cmd . 'id'])) {
$scheduleForUpdate = true;
}
}
if ($scheduleForUpdate) {
unset($insertData[$mapping['name']]);
$this->uow->scheduleExtraUpdate($document, array(
$mapping['fieldName'] => array(null, $new)
));
}
}
}
// add discriminator if the class has one
if ($class->hasDiscriminator()) {
$insertData[$class->discriminatorField['name']] = $class->discriminatorValue;
}
return $insertData;
}
示例2: prepareInsertData
/**
* Prepares the array that is ready to be inserted to mongodb for a given object document.
*
* @param object $document
* @return array $insertData
*/
public function prepareInsertData($document)
{
$class = $this->dm->getClassMetadata(get_class($document));
$changeset = $this->uow->getDocumentChangeSet($document);
$insertData = array();
foreach ($class->fieldMappings as $mapping) {
// many collections are inserted later
if ($mapping['type'] === ClassMetadata::MANY) {
continue;
}
// skip not saved fields
if (isset($mapping['notSaved']) && $mapping['notSaved'] === true) {
continue;
}
// Skip version and lock fields
if (isset($mapping['version']) || isset($mapping['lock'])) {
continue;
}
$new = isset($changeset[$mapping['fieldName']][1]) ? $changeset[$mapping['fieldName']][1] : null;
// Generate a document identifier
if ($new === null && $class->identifier === $mapping['fieldName'] && $class->generatorType !== ClassMetadata::GENERATOR_TYPE_NONE) {
$new = $class->idGenerator->generate($this->dm, $document);
}
// Don't store null values unless nullable === true
if ($new === null && $mapping['nullable'] === false) {
continue;
}
$value = null;
if ($new !== null) {
// @Field, @String, @Date, etc.
if (!isset($mapping['association'])) {
$value = Type::getType($mapping['type'])->convertToDatabaseValue($new);
// @ReferenceOne
} elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::REFERENCE_ONE) {
if ($mapping['isInverseSide']) {
continue;
}
$oid = spl_object_hash($new);
if ($this->isScheduledForInsert($new)) {
// The associated document $new is not yet persisted, so we must
// set $new = null, in order to insert a null value and schedule an
// extra update on the UnitOfWork.
$this->uow->scheduleExtraUpdate($document, array($mapping['fieldName'] => array(null, $new)));
} else {
$value = $this->prepareReferencedDocumentValue($mapping, $new);
}
// @EmbedOne
} elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::EMBED_ONE) {
$value = $this->prepareEmbeddedDocumentValue($mapping, $new);
// @ReferenceMany
} elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::REFERENCE_MANY) {
$value = array();
foreach ($new as $reference) {
$value[] = $this->prepareReferenceDocValue($mapping, $reference);
}
// @EmbedMany
} elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::EMBED_MANY) {
$value = array();
foreach ($new as $reference) {
$value[] = $this->prepareEmbeddedDocumentValue($mapping, $reference);
}
}
}
$insertData[$mapping['name']] = $value;
}
// add discriminator if the class has one
if ($class->hasDiscriminator()) {
$insertData[$class->discriminatorField['name']] = $class->discriminatorValue;
}
return $insertData;
}