class DocumentPersister (View source)

The DocumentPersister is responsible for persisting documents.

Methods

__construct(PersistenceBuilder $pb, DocumentManager $dm, UnitOfWork $uow, HydratorFactory $hydratorFactory, ClassMetadata $class, CriteriaMerger|null $cm = null)

No description

getInserts()

No description

isQueuedForInsert(object $document)

No description

addInsert(object $document)

Adds a document to the queued insertions.

getUpserts()

No description

isQueuedForUpsert(object $document)

No description

addUpsert(object $document)

Adds a document to the queued upserts.

getClassMetadata()

Gets the ClassMetadata instance of the document class this persister is used for.

executeInserts(array $options = [])

Executes all queued document insertions.

executeUpserts(array $options = [])

Executes all queued document upserts.

update(object $document, array $options = [])

Updates the already persisted document if it has any new changesets.

delete(object $document, array $options = [])

Removes document from mongo

refresh(object $document)

Refreshes a managed document.

load($criteria, object|null $document = null, array $hints = [], int $lockMode = 0, array|null $sort = null)

Finds a document by a set of criteria.

loadAll(array $criteria = [], array|null $sort = null, int|null $limit = null, int|null $skip = null)

Finds documents by a set of criteria.

exists(object $document)

Checks whether the given managed document exists in the database.

lock(object $document, int $lockMode)

Locks document by storing the lock mode on the mapped lock field.

unlock(object $document)

Releases any lock that exists on this document.

loadCollection(PersistentCollectionInterface $collection)

Loads a PersistentCollection data. Used in the initialize() method.

prepareProjection(array $fields)

Prepare a projection array by converting keys, which are PHP property names, to MongoDB field names.

prepareSort(array $fields)

Prepare a sort specification array by converting keys to MongoDB field names and changing direction strings to int.

prepareFieldName(string $fieldName)

Prepare a mongodb field name and convert the PHP property names to MongoDB field names.

addDiscriminatorToPreparedQuery(array $preparedQuery)

Adds discriminator criteria to an already-prepared query.

addFilterToPreparedQuery(array $preparedQuery)

Adds filter criteria to an already-prepared query.

prepareQueryOrNewObj(array $query, bool $isNewObj = false)

Prepares the query criteria or new document object.

Details

__construct(PersistenceBuilder $pb, DocumentManager $dm, UnitOfWork $uow, HydratorFactory $hydratorFactory, ClassMetadata $class, CriteriaMerger|null $cm = null)

Parameters

PersistenceBuilder $pb
DocumentManager $dm
UnitOfWork $uow
HydratorFactory $hydratorFactory
ClassMetadata $class
CriteriaMerger|null $cm

getInserts()

isQueuedForInsert(object $document)

Parameters

object $document

addInsert(object $document)

Adds a document to the queued insertions.

The document remains queued until {@link executeInserts} is invoked.

Parameters

object $document

getUpserts()

isQueuedForUpsert(object $document)

Parameters

object $document

addUpsert(object $document)

Adds a document to the queued upserts.

The document remains queued until {@link executeUpserts} is invoked.

Parameters

object $document

getClassMetadata()

Gets the ClassMetadata instance of the document class this persister is used for.

executeInserts(array $options = [])

Executes all queued document insertions.

Queued documents without an ID will inserted in a batch and queued documents with an ID will be upserted individually.

If no inserts are queued, invoking this method is a NOOP.

Parameters

array $options

Exceptions

Exception

executeUpserts(array $options = [])

Executes all queued document upserts.

Queued documents with an ID are upserted individually.

If no upserts are queued, invoking this method is a NOOP.

Parameters

array $options

update(object $document, array $options = [])

Updates the already persisted document if it has any new changesets.

Parameters

object $document
array $options

Exceptions

LockException

delete(object $document, array $options = [])

Removes document from mongo

Parameters

object $document
array $options

Exceptions

LockException

refresh(object $document)

Refreshes a managed document.

Parameters

object $document

load($criteria, object|null $document = null, array $hints = [], int $lockMode = 0, array|null $sort = null)

Finds a document by a set of criteria.

If a scalar or MongoDB\BSON\ObjectId is provided for $criteria, it will be used to match an _id value.

Parameters

$criteria
object|null $document
array $hints
int $lockMode
array|null $sort

Exceptions

LockException

loadAll(array $criteria = [], array|null $sort = null, int|null $limit = null, int|null $skip = null)

Finds documents by a set of criteria.

Parameters

array $criteria
array|null $sort
int|null $limit
int|null $skip

exists(object $document)

Checks whether the given managed document exists in the database.

Parameters

object $document

lock(object $document, int $lockMode)

Locks document by storing the lock mode on the mapped lock field.

Parameters

object $document
int $lockMode

unlock(object $document)

Releases any lock that exists on this document.

Parameters

object $document

loadCollection(PersistentCollectionInterface $collection)

Loads a PersistentCollection data. Used in the initialize() method.

Parameters

PersistentCollectionInterface $collection

createReferenceManyInverseSideQuery(PersistentCollectionInterface $collection)

Parameters

PersistentCollectionInterface $collection

createReferenceManyWithRepositoryMethodCursor(PersistentCollectionInterface $collection)

Parameters

PersistentCollectionInterface $collection

prepareProjection(array $fields)

Prepare a projection array by converting keys, which are PHP property names, to MongoDB field names.

Parameters

array $fields

prepareSort(array $fields)

Prepare a sort specification array by converting keys to MongoDB field names and changing direction strings to int.

Parameters

array $fields

prepareFieldName(string $fieldName)

Prepare a mongodb field name and convert the PHP property names to MongoDB field names.

Parameters

string $fieldName

addDiscriminatorToPreparedQuery(array $preparedQuery)

Adds discriminator criteria to an already-prepared query.

This method should be used once for query criteria and not be used for nested expressions. It should be called before {@link DocumentPerister::addFilterToPreparedQuery()}.

Parameters

array $preparedQuery

addFilterToPreparedQuery(array $preparedQuery)

Adds filter criteria to an already-prepared query.

This method should be used once for query criteria and not be used for nested expressions. It should be called after {@link DocumentPerister::addDiscriminatorToPreparedQuery()}.

Parameters

array $preparedQuery

prepareQueryOrNewObj(array $query, bool $isNewObj = false)

Prepares the query criteria or new document object.

PHP field names and types will be converted to those used by MongoDB.

Parameters

array $query
bool $isNewObj