当前位置: 首页>>代码示例>>PHP>>正文


PHP MongoDB\UnitOfWork类代码示例

本文整理汇总了PHP中Doctrine\ODM\MongoDB\UnitOfWork的典型用法代码示例。如果您正苦于以下问题:PHP UnitOfWork类的具体用法?PHP UnitOfWork怎么用?PHP UnitOfWork使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了UnitOfWork类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1:

 function it_schedules_owning_document_for_update_when_setting_element_by_key_in_the_collection(MongoDBODMUnitOfWork $uow, DocumentStub $document, ObjectRepository $repository, ClassMetadata $classMetadata, EntityStub $entity4, EntityStub $entity8, EntityStub $entity15, EntityStub $newEntity)
 {
     $classMetadata->getIdentifier()->willReturn(['id']);
     $repository->findBy(['id' => [4, 8, 15]])->willReturn([$entity4, $entity8, $entity15]);
     $uow->getDocumentState($document)->willReturn(MongoDBODMUnitOfWork::STATE_MANAGED);
     $uow->isScheduledForUpdate($document)->willReturn(false);
     $uow->scheduleForUpdate($document)->shouldBeCalled();
     $this->setOwner($document);
     $this->set(2, $newEntity);
 }
开发者ID:javiersantos,项目名称:pim-community-dev,代码行数:10,代码来源:ReferencedCollectionSpec.php

示例2: process

 /**
  * @param PermissionsAwareInterface[] $documents
  * @param DocumentManager $dm
  * @param UnitOfWork $uow
  * @param bool $insert
  */
 protected function process($documents, DocumentManager $dm, UnitOfWork $uow, $insert = false)
 {
     foreach ($documents as $document) {
         $perms = $document->getPermissions();
         $files = $this->getFiles($document);
         foreach ($files as $file) {
             $filePermissions = $file->getPermissions()->clear()->inherit($perms);
             if ($insert) {
                 $dm->persist($filePermissions);
             }
             $uow->computeChangeSet($dm->getClassMetadata(get_class($file)), $file);
         }
     }
 }
开发者ID:cross-solution,项目名称:yawik,代码行数:20,代码来源:AbstractUpdateFilesPermissionsSubscriber.php

示例3: current

 /**
  * @see \Doctrine\MongoDB\EagerCursor::current()
  * @see http://php.net/manual/en/iterator.current.php
  */
 public function current()
 {
     $current = parent::current();
     if ($current === null || !$this->hydrate) {
         return $current;
     }
     return $this->unitOfWork->getOrCreateDocument($this->class->name, $current, $this->unitOfWorkHints);
 }
开发者ID:im286er,项目名称:ent,代码行数:12,代码来源:EagerCursor.php

示例4: prepareReferencedDocValue

    /**
     * Returns the reference representation to be stored in mongodb or null if not applicable.
     *
     * @param array $referenceMapping
     * @param Document $document
     * @return array|null
     */
    public function prepareReferencedDocValue(array $referenceMapping, $document)
    {
        $id = null;
        if (is_array($document)) {
            $className = $referenceMapping['targetDocument'];
        } else {
            $className = get_class($document);
            $id = $this->uow->getDocumentIdentifier($document);
        }
        $class = $this->dm->getClassMetadata($className);
        if (null !== $id) {
            $id = $class->getDatabaseIdentifierValue($id);
        }
        $ref = array(
            $this->cmd . 'ref' => $class->getCollection(),
            $this->cmd . 'id' => $id,
            $this->cmd . 'db' => $class->getDatabase()
        );

        // Store a discriminator value if the referenced document is not mapped explicitely to a targetDocument
        if ( ! isset($referenceMapping['targetDocument'])) {
            $discriminatorField = isset($referenceMapping['discriminatorField']) ? $referenceMapping['discriminatorField'] : '_doctrine_class_name';
            $discriminatorValue = isset($referenceMapping['discriminatorMap']) ? array_search($class->getName(), $referenceMapping['discriminatorMap']) : $class->getName();
            $ref[$discriminatorField] = $discriminatorValue;
        }
        return $ref;
    }
开发者ID:pmjones,项目名称:php-framework-benchmarks,代码行数:34,代码来源:PersistenceBuilder.php

示例5: loadReferenceManyCollection

 private function loadReferenceManyCollection(PersistentCollection $collection)
 {
     $mapping = $collection->getMapping();
     $cmd = $this->cmd;
     $groupedIds = array();
     foreach ($collection->getMongoData() as $reference) {
         $className = $this->dm->getClassNameFromDiscriminatorValue($mapping, $reference);
         $mongoId = $reference[$cmd . 'id'];
         $id = (string) $mongoId;
         $reference = $this->dm->getReference($className, $id);
         $collection->add($reference);
         if ($reference instanceof Proxy && !$reference->__isInitialized__) {
             if (!isset($groupedIds[$className])) {
                 $groupedIds[$className] = array();
             }
             $groupedIds[$className][] = $mongoId;
         }
     }
     foreach ($groupedIds as $className => $ids) {
         $class = $this->dm->getClassMetadata($className);
         $mongoCollection = $this->dm->getDocumentCollection($className);
         $data = $mongoCollection->find(array('_id' => array($cmd . 'in' => $ids)));
         foreach ($data as $documentData) {
             $document = $this->uow->getById((string) $documentData['_id'], $class->rootDocumentName);
             $data = $this->hydratorFactory->hydrate($document, $documentData);
             $this->uow->setOriginalDocumentData($document, $data);
         }
     }
 }
开发者ID:jackbravo,项目名称:symfony-sandbox,代码行数:29,代码来源:DocumentPersister.php

示例6: getAtomicCollectionUpdateQuery

 private function getAtomicCollectionUpdateQuery($document)
 {
     $update = array();
     $collections = $this->uow->getScheduledCollections($document);
     $collPersister = $this->uow->getCollectionPersister();
     foreach ($collections as $coll) {
         /* @var $coll PersistentCollection */
         $mapping = $coll->getMapping();
         if ($mapping['strategy'] !== "atomicSet" && $mapping['strategy'] !== "atomicSetArray") {
             continue;
         }
         if ($this->uow->isCollectionScheduledForUpdate($coll)) {
             $update = array_merge_recursive($update, $collPersister->prepareSetQuery($coll));
             $this->uow->unscheduleCollectionUpdate($coll);
             /* TODO:
              * Collection can be set for both deletion and update if
              * PersistentCollection instance was changed. Since we're dealing
              * with collection update in one query we won't need the $unset.
              * Line can be removed once the issue is fixed.
              */
             $this->uow->unscheduleCollectionDeletion($coll);
         } elseif ($this->uow->isCollectionScheduledForDeletion($coll)) {
             $update = array_merge_recursive($update, $collPersister->prepareDeleteQuery($coll));
             $this->uow->unscheduleCollectionDeletion($coll);
         }
     }
     return $update;
 }
开发者ID:uedehua,项目名称:laravel5-mongodb,代码行数:28,代码来源:DocumentPersister.php

示例7: getIdentifierValue

 /**
  * Returns the value of the identifier field of a document
  *
  * Doctrine must know about this document, that is, the document must already
  * be persisted or added to the identity map before. Otherwise an
  * exception is thrown.
  *
  * @param  object $document  The document for which to get the identifier
  * @throws FormException   If the document does not exist in Doctrine's
  *                         identity map
  */
 public function getIdentifierValue($document)
 {
     if (!$this->unitOfWork->isInIdentityMap($document)) {
         throw new FormException('documents passed to the choice field must be managed');
     }
     return $this->unitOfWork->getDocumentIdentifier($document);
 }
开发者ID:3116246,项目名称:haolinju,代码行数:18,代码来源:DocumentChoiceList.php

示例8: loadCollection

    public function loadCollection(PersistentCollection $collection)
    {
        $mapping = $collection->getMapping();
        $cmd = $this->dm->getConfiguration()->getMongoCmd();
        $groupedIds = array();
        foreach ($collection->getReferences() as $reference) {
            $className = $this->dm->getClassNameFromDiscriminatorValue($mapping, $reference);
            $id = $reference[$cmd . 'id'];
            $reference = $this->dm->getReference($className, (string) $id);
            $collection->add($reference);
            if ($reference instanceof Proxy && ! $reference->__isInitialized__) {
                if ( ! isset($groupedIds[$className])) {
                    $groupedIds[$className] = array();
                }
                $groupedIds[$className][] = $id;
            }
        }

        foreach ($groupedIds as $className => $ids) {
            $mongoCollection = $this->dm->getDocumentCollection($className);
            $data = $mongoCollection->find(array('_id' => array($cmd . 'in' => $ids)));
            $hints = array(Builder::HINT_REFRESH => true);
            foreach ($data as $id => $documentData) {
                $document = $this->uow->getOrCreateDocument($className, $documentData, $hints);
            }
        }
    }
开发者ID:pmjones,项目名称:php-framework-benchmarks,代码行数:27,代码来源:DocumentPersister.php

示例9: hydrateDocument

 /**
  * @param array $document
  * @return array|object|null
  */
 private function hydrateDocument($document)
 {
     if ($document !== null && $this->class !== null) {
         return $this->unitOfWork->getOrCreateDocument($this->class->name, $document);
     }
     return $document;
 }
开发者ID:doctrine,项目名称:mongodb-odm,代码行数:11,代码来源:CommandCursor.php

示例10: createReferenceManyInverseSideQuery

 /**
  * @param PersistentCollection $collection
  *
  * @return Query
  */
 public function createReferenceManyInverseSideQuery(PersistentCollection $collection)
 {
     $hints = $collection->getHints();
     $mapping = $collection->getMapping();
     $owner = $collection->getOwner();
     $ownerClass = $this->dm->getClassMetadata(get_class($owner));
     $targetClass = $this->dm->getClassMetadata($mapping['targetDocument']);
     $mappedByMapping = isset($targetClass->fieldMappings[$mapping['mappedBy']]) ? $targetClass->fieldMappings[$mapping['mappedBy']] : array();
     $mappedByFieldName = isset($mappedByMapping['simple']) && $mappedByMapping['simple'] ? $mapping['mappedBy'] : $mapping['mappedBy'] . '.$id';
     $criteria = $this->cm->merge(array($mappedByFieldName => $ownerClass->getIdentifierObject($owner)), $this->dm->getFilterCollection()->getFilterCriteria($targetClass), isset($mapping['criteria']) ? $mapping['criteria'] : array());
     $criteria = $this->uow->getDocumentPersister($mapping['targetDocument'])->prepareQueryOrNewObj($criteria);
     $qb = $this->dm->createQueryBuilder($mapping['targetDocument'])->setQueryArray($criteria);
     if (isset($mapping['sort'])) {
         $qb->sort($mapping['sort']);
     }
     if (isset($mapping['limit'])) {
         $qb->limit($mapping['limit']);
     }
     if (isset($mapping['skip'])) {
         $qb->skip($mapping['skip']);
     }
     if (!empty($hints[Query::HINT_SLAVE_OKAY])) {
         $qb->slaveOkay(true);
     }
     if (!empty($hints[Query::HINT_READ_PREFERENCE])) {
         $qb->setReadPreference($hints[Query::HINT_READ_PREFERENCE], $hints[Query::HINT_READ_PREFERENCE_TAGS]);
     }
     return $qb->getQuery();
 }
开发者ID:im286er,项目名称:ent,代码行数:34,代码来源:DocumentPersister.php

示例11: getQueryForDocument

 /**
  * Get shard key aware query for single document.
  *
  * @param object $document
  *
  * @return array
  */
 private function getQueryForDocument($document)
 {
     $id = $this->uow->getDocumentIdentifier($document);
     $id = $this->class->getDatabaseIdentifierValue($id);
     $shardKeyQueryPart = $this->getShardKeyQuery($document);
     $query = array_merge(array('_id' => $id), $shardKeyQueryPart);
     return $query;
 }
开发者ID:dominium,项目名称:mongodb-odm,代码行数:15,代码来源:DocumentPersister.php

示例12: loadReferenceManyCollectionOwningSide

 private function loadReferenceManyCollectionOwningSide(PersistentCollection $collection)
 {
     $hints = $collection->getHints();
     $mapping = $collection->getMapping();
     $cmd = $this->cmd;
     $groupedIds = array();
     foreach ($collection->getMongoData() as $key => $reference) {
         if (isset($mapping['simple']) && $mapping['simple']) {
             $className = $mapping['targetDocument'];
             $mongoId = $reference;
         } else {
             $className = $this->dm->getClassNameFromDiscriminatorValue($mapping, $reference);
             $mongoId = $reference[$cmd . 'id'];
         }
         $id = (string) $mongoId;
         if (!$id) {
             continue;
         }
         $reference = $this->dm->getReference($className, $id);
         if ($mapping['strategy'] === 'set') {
             $collection->set($key, $reference);
         } else {
             $collection->add($reference);
         }
         if ($reference instanceof Proxy && !$reference->__isInitialized__) {
             if (!isset($groupedIds[$className])) {
                 $groupedIds[$className] = array();
             }
             $groupedIds[$className][] = $mongoId;
         }
     }
     foreach ($groupedIds as $className => $ids) {
         $class = $this->dm->getClassMetadata($className);
         $mongoCollection = $this->dm->getDocumentCollection($className);
         $criteria = array_merge(array('_id' => array($cmd . 'in' => $ids)), $this->dm->getFilterCollection()->getFilterCriteria($class), isset($mapping['criteria']) ? $mapping['criteria'] : array());
         $cursor = $mongoCollection->find($criteria);
         if (isset($mapping['sort'])) {
             $cursor->sort($mapping['sort']);
         }
         if (isset($mapping['limit'])) {
             $cursor->limit($mapping['limit']);
         }
         if (isset($mapping['skip'])) {
             $cursor->skip($mapping['skip']);
         }
         if (isset($hints[Query::HINT_SLAVE_OKAY])) {
             $cursor->slaveOkay(true);
         }
         $documents = $cursor->toArray();
         foreach ($documents as $documentData) {
             $document = $this->uow->getById((string) $documentData['_id'], $class->rootDocumentName);
             $data = $this->hydratorFactory->hydrate($document, $documentData);
             $this->uow->setOriginalDocumentData($document, $data);
             $document->__isInitialized__ = true;
         }
     }
 }
开发者ID:3116246,项目名称:haolinju,代码行数:57,代码来源:DocumentPersister.php

示例13: doSet

 /**
  * Actual logic for setting an element in the collection.
  *
  * @param mixed $offset
  * @param mixed $value
  * @param bool $arrayAccess
  * @return bool
  */
 private function doSet($offset, $value, $arrayAccess)
 {
     $arrayAccess ? $this->coll->offsetSet($offset, $value) : $this->coll->set($offset, $value);
     // Handle orphanRemoval
     if ($this->uow !== null && $this->isOrphanRemovalEnabled() && $value !== null) {
         $this->uow->unscheduleOrphanRemoval($value);
     }
     $this->changed();
 }
开发者ID:alcaeus,项目名称:mongodb-odm,代码行数:17,代码来源:PersistentCollectionTrait.php

示例14: _prepareDocReference

 /**
  * Returns the reference representation to be stored in mongodb or null if not applicable.
  *
  * @param ClassMetadata $class
  * @param Document $doc
  * @return array|null
  */
 private function _prepareDocReference(ClassMetadata $class, $doc)
 {
     if (!is_object($doc)) {
         return $doc;
     }
     $id = $this->_uow->getDocumentIdentifier($doc);
     if (null !== $id) {
         $id = $class->getPHPIdentifierValue($id);
     }
     $ref = array($this->_cmd . 'ref' => $class->getCollection(), $this->_cmd . 'id' => $id, $this->_cmd . 'db' => $class->getDB());
     return $ref;
 }
开发者ID:klaasn,项目名称:symfony-sandbox,代码行数:19,代码来源:BasicDocumentPersister.php

示例15: isPartOfAtomicUpdate

 /**
  * @param object $embeddeDoc
  * @return bool
  */
 private function isPartOfAtomicUpdate($embeddeDoc)
 {
     $isInDirtyCollection = false;
     while (null !== ($parentAssoc = $this->uow->getParentAssociation($embeddeDoc))) {
         list($mapping, $embeddeDoc, ) = $parentAssoc;
         if ($mapping['association'] === ClassMetadata::EMBED_MANY) {
             $classMetadata = $this->dm->getClassMetadata(get_class($embeddeDoc));
             $parentColl = $classMetadata->getFieldValue($embeddeDoc, $mapping['fieldName']);
             $isInDirtyCollection |= $parentColl->isDirty();
         }
     }
     return isset($mapping['association']) && $mapping['association'] === ClassMetadata::EMBED_MANY && ($mapping['strategy'] === 'atomicSet' || $mapping['strategy'] === 'atomicSetArray') && $isInDirtyCollection;
 }
开发者ID:noc-med,项目名称:mongodb-odm,代码行数:17,代码来源:PersistenceBuilder.php


注:本文中的Doctrine\ODM\MongoDB\UnitOfWork类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。