INTERNAL:
Creates a document. Used for reconstitution of documents during hydration.
public getOrCreateDocument ( string $className, array $data, array &$hints = [], object $document = null ) : object | ||
$className | string | The name of the document class. |
$data | array | The data for the document. |
$hints | array | Any hints to account for during reconstitution/lookup of the document. |
$document | object | The document to be hydrated into in case of creation |
리턴 | object | The document instance. |
/** * @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); }
/** * @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; }
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); } } }
/** * Lood document by its identifier. * * @param string $id * @return object|null */ public function loadById($id) { $result = $this->collection->findOne(array('_id' => $this->class->getDatabaseIdentifierValue($id))); if ($result !== null) { return $this->uow->getOrCreateDocument($this->documentName, $result); } return null; }
/** * Wrapper method for MongoCursor::getNext(). * * If configured, the result may be a hydrated document class instance. * * @see \Doctrine\MongoDB\Cursor::getNext() * @see http://php.net/manual/en/mongocursor.getnext.php * @return array|object|null */ public function getNext() { $next = $this->baseCursor->getNext(); if ($next !== null && $this->hydrate) { return $this->unitOfWork->getOrCreateDocument($this->class->name, $next, $this->unitOfWorkHints); } return $next; }
/** * Lood document by its identifier. * * @param string $id * @return object|null */ public function loadById($id) { $result = $this->_collection->findOne(array('_id' => $this->_class->getDatabaseIdentifierValue($id))); if ($result !== null) { $document = $this->_uow->getOrCreateDocument($this->_documentName, $result); $this->_uow->registerManaged($document, $this->_class->getPHPIdentifierValue($result['_id']), $result); return $document; } return null; }
/** * Creates or fills a single document object from an query result. * * @param object $result The query result. * @param object $document The document object to fill, if any. * @param array $hints Hints for document creation. * @return object The filled and managed document object or NULL, if the query result is empty. */ private function createDocument($result, $document = null, array $hints = array()) { if ($result === null) { return null; } if ($document !== null) { $hints[Query::HINT_REFRESH] = true; $id = $this->class->getPHPIdentifierValue($result['_id']); $this->uow->registerManaged($document, $id, $result); } return $this->uow->getOrCreateDocument($this->class->name, $result, $hints, $document); }