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


PHP UnitOfWork::getClassNameForAssociation方法代码示例

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


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

示例1: loadReferenceManyCollectionOwningSide

 private function loadReferenceManyCollectionOwningSide(PersistentCollection $collection)
 {
     $mapping = $collection->getMapping();
     $groupedIds = array();
     $sorted = isset($mapping['sort']) && $mapping['sort'];
     foreach ($collection->getMongoData() as $key => $reference) {
         if (isset($mapping['simple']) && $mapping['simple']) {
             $className = $mapping['targetDocument'];
             $mongoId = $reference;
         } else {
             $className = $this->uow->getClassNameForAssociation($mapping, $reference);
             $mongoId = $reference['$id'];
         }
         $id = $this->dm->getClassMetadata($className)->getPHPIdentifierValue($mongoId);
         $reference = $this->dm->getReference($className, $id);
         /* If the reference has custom sort, remember IDs to execute the query later.
          * Otherwise add the references right now in the order they are embedded.
          */
         if ($sorted) {
             $groupedIds[$className][] = $mongoId;
         } else {
             if ($mapping['strategy'] === 'set') {
                 $collection->set($key, $reference);
             } else {
                 $collection->add($reference);
             }
         }
     }
     if ($sorted && count($groupedIds)) {
         $this->loadActualDataForSortedReferenceManyCollectionByIds($collection, $groupedIds);
     }
 }
开发者ID:briareos,项目名称:mongodb-odm,代码行数:32,代码来源:DocumentPersister.php

示例2: addManyReferences

 /**
  * Adds identifiers from a PersistentCollection to $groupedIds.
  *
  * If the relation contains simple references, the mapping is assumed to
  * have a target document class defined. Without that, there is no way to
  * infer the class of the referenced documents.
  *
  * @param PersistentCollection $persistentCollection
  * @param array                $groupedIds
  */
 private function addManyReferences(PersistentCollection $persistentCollection, array &$groupedIds)
 {
     $mapping = $persistentCollection->getMapping();
     if (!empty($mapping['simple'])) {
         $className = $mapping['targetDocument'];
         $class = $this->dm->getClassMetadata($className);
     }
     foreach ($persistentCollection->getMongoData() as $reference) {
         if (!empty($mapping['simple'])) {
             $id = $reference;
         } else {
             $id = $reference['$id'];
             $className = $this->uow->getClassNameForAssociation($mapping, $reference);
             $class = $this->dm->getClassMetadata($className);
         }
         $document = $this->uow->tryGetById($id, $class);
         if (!$document || $document instanceof Proxy && !$document->__isInitialized()) {
             $id = $class->getPHPIdentifierValue($id);
             $groupedIds[$className][serialize($id)] = $id;
         }
     }
 }
开发者ID:EngrHaiderAli,项目名称:movein-servie,代码行数:32,代码来源:ReferencePrimer.php

示例3: loadReferenceManyCollectionOwningSide

 private function loadReferenceManyCollectionOwningSide(PersistentCollection $collection)
 {
     $hints = $collection->getHints();
     $mapping = $collection->getMapping();
     $groupedIds = array();
     $sorted = isset($mapping['sort']) && $mapping['sort'];
     foreach ($collection->getMongoData() as $key => $reference) {
         if (isset($mapping['simple']) && $mapping['simple']) {
             $className = $mapping['targetDocument'];
             $mongoId = $reference;
         } else {
             $className = $this->uow->getClassNameForAssociation($mapping, $reference);
             $mongoId = $reference['$id'];
         }
         $id = $this->dm->getClassMetadata($className)->getPHPIdentifierValue($mongoId);
         // create a reference to the class and id
         $reference = $this->dm->getReference($className, $id);
         // no custom sort so add the references right now in the order they are embedded
         if (!$sorted) {
             if (CollectionHelper::isHash($mapping['strategy'])) {
                 $collection->set($key, $reference);
             } else {
                 $collection->add($reference);
             }
         }
         // only query for the referenced object if it is not already initialized or the collection is sorted
         if ($reference instanceof Proxy && !$reference->__isInitialized__ || $sorted) {
             $groupedIds[$className][] = $mongoId;
         }
     }
     foreach ($groupedIds as $className => $ids) {
         $class = $this->dm->getClassMetadata($className);
         $mongoCollection = $this->dm->getDocumentCollection($className);
         $criteria = $this->cm->merge(array('_id' => array('$in' => array_values($ids))), $this->dm->getFilterCollection()->getFilterCriteria($class), isset($mapping['criteria']) ? $mapping['criteria'] : array());
         $criteria = $this->uow->getDocumentPersister($className)->prepareQueryOrNewObj($criteria);
         $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 (!empty($hints[Query::HINT_SLAVE_OKAY])) {
             $cursor->slaveOkay(true);
         }
         if (!empty($hints[Query::HINT_READ_PREFERENCE])) {
             $cursor->setReadPreference($hints[Query::HINT_READ_PREFERENCE], $hints[Query::HINT_READ_PREFERENCE_TAGS]);
         }
         $documents = $cursor->toArray(false);
         foreach ($documents as $documentData) {
             $document = $this->uow->getById($documentData['_id'], $class);
             $data = $this->hydratorFactory->hydrate($document, $documentData);
             $this->uow->setOriginalDocumentData($document, $data);
             $document->__isInitialized__ = true;
             if ($sorted) {
                 $collection->add($document);
             }
         }
     }
 }
开发者ID:ttk04,项目名称:mongodb-odm,代码行数:63,代码来源:DocumentPersister.php

示例4: testGetClassNameForAssociationWithClassMetadataDiscriminatorMap

 public function testGetClassNameForAssociationWithClassMetadataDiscriminatorMap()
 {
     $dm = $this->getMockDocumentManager();
     $uow = new UnitOfWork($dm, $this->getMockEventManager(), $this->getMockHydratorFactory());
     $mapping = array('targetDocument' => 'Documents\\User');
     $data = array('type' => 'forum_user');
     $userClassMetadata = new ClassMetadata('Documents\\ForumUser');
     $userClassMetadata->discriminatorField = 'type';
     $userClassMetadata->discriminatorMap = array('forum_user' => 'Documents\\ForumUser');
     $dm->expects($this->once())->method('getClassMetadata')->with('Documents\\User')->will($this->returnValue($userClassMetadata));
     $this->assertEquals('Documents\\ForumUser', $uow->getClassNameForAssociation($mapping, $data));
 }
开发者ID:noc-med,项目名称:mongodb-odm,代码行数:12,代码来源:UnitOfWorkTest.php


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