本文整理汇总了PHP中Doctrine\ODM\MongoDB\UnitOfWork::getDocumentPersister方法的典型用法代码示例。如果您正苦于以下问题:PHP UnitOfWork::getDocumentPersister方法的具体用法?PHP UnitOfWork::getDocumentPersister怎么用?PHP UnitOfWork::getDocumentPersister使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ODM\MongoDB\UnitOfWork
的用法示例。
在下文中一共展示了UnitOfWork::getDocumentPersister方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
}
示例2: count
/**
* {@inheritdoc}
*/
public function count()
{
$count = $this->coll->count();
// If this collection is inversed and not initialized, add the count returned from the database
if ($this->mapping['isInverseSide'] && !$this->initialized) {
$documentPersister = $this->uow->getDocumentPersister(get_class($this->owner));
$count += empty($this->mapping['repositoryMethod']) ? $documentPersister->createReferenceManyInverseSideQuery($this)->count() : $documentPersister->createReferenceManyWithRepositoryMethodCursor($this)->count();
}
return $count + ($this->initialized ? 0 : count($this->mongoData));
}
示例3: count
/**
* {@inheritdoc}
*/
public function count()
{
if ($this->mapping['isInverseSide'] && !$this->initialized) {
$documentPersister = $this->uow->getDocumentPersister(get_class($this->owner));
$count = empty($this->mapping['repositoryMethod']) ? $documentPersister->createReferenceManyInverseSideQuery($this)->count() : $documentPersister->createReferenceManyWithRepositoryMethodCursor($this)->count();
} else {
$count = $this->coll->count();
}
return count($this->mongoData) + $count;
}
示例4: loadActualDataForSortedReferenceManyCollectionByIds
/**
* @param PersistentCollection $collection
* @param array $groupedIds
*
* @throws \Doctrine\ODM\MongoDB\MongoDBException
*/
private function loadActualDataForSortedReferenceManyCollectionByIds(PersistentCollection $collection, array $groupedIds)
{
$mapping = $collection->getMapping();
$hints = $collection->getHints();
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) {
$docId = $documentData['_id'];
$document = $this->uow->getById($docId, $class);
$data = $this->hydratorFactory->hydrate($document, $documentData);
$this->uow->setOriginalDocumentData($document, $data);
$document->__isInitialized__ = true;
$collection->add($document);
}
}
}
示例5: isScheduledForInsert
/**
* @param object $document
* @return boolean
*/
private function isScheduledForInsert($document)
{
return $this->uow->isScheduledForInsert($document) || $this->uow->getDocumentPersister(get_class($document))->isQueuedForInsert($document);
}
示例6: getDocumentPersister
protected function getDocumentPersister()
{
return $this->uow->getDocumentPersister($this->documentName);
}
示例7: findOneBy
/**
* Finds a single document by a set of criteria.
*
* @param array $criteria
* @return object
*/
public function findOneBy(array $criteria)
{
return $this->uow->getDocumentPersister($this->documentName)->load($criteria);
}
示例8: getDocumentPersister
/**
* @override
*/
public function getDocumentPersister($documentName)
{
return isset($this->_persisterMock[$documentName]) ? $this->_persisterMock[$documentName] : parent::getDocumentPersister($documentName);
}
示例9: sort
/**
* Wrapper method for MongoCursor::sort().
*
* Field names will be prepared according to the document mapping.
*
* @see \Doctrine\MongoDB\Cursor::sort()
* @see http://php.net/manual/en/mongocursor.sort.php
* @param array $fields
* @return self
*/
public function sort($fields)
{
$fields = $this->unitOfWork->getDocumentPersister($this->class->name)->prepareSortOrProjection($fields);
$this->baseCursor->sort($fields);
return $this;
}