當前位置: 首頁>>代碼示例>>PHP>>正文


PHP UnitOfWork::scheduleExtraUpdate方法代碼示例

本文整理匯總了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;
    }
開發者ID:pmjones,項目名稱:php-framework-benchmarks,代碼行數:65,代碼來源:PersistenceBuilder.php

示例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;
 }
開發者ID:roed,項目名稱:mongodb-odm,代碼行數:77,代碼來源:PersistenceBuilder.php


注:本文中的Doctrine\ODM\MongoDB\UnitOfWork::scheduleExtraUpdate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。