本文整理汇总了PHP中Doctrine\ODM\MongoDB\UnitOfWork::getOrCreateDocument方法的典型用法代码示例。如果您正苦于以下问题:PHP UnitOfWork::getOrCreateDocument方法的具体用法?PHP UnitOfWork::getOrCreateDocument怎么用?PHP UnitOfWork::getOrCreateDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ODM\MongoDB\UnitOfWork
的用法示例。
在下文中一共展示了UnitOfWork::getOrCreateDocument方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: 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;
}
示例3: 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);
}
}
}
示例4: loadById
/**
* 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;
}
示例5: getNext
/**
* 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;
}
示例6: loadById
/**
* 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;
}
示例7: createDocument
/**
* 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);
}