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)

Initializes this instance.

array
getInserts()

No description

bool
isQueuedForInsert(object $document)

No description

addInsert(object $document)

Adds a document to the queued insertions.

array
getUpserts()

No description

bool
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(mixed $document, array $options = [])

Removes document from mongo

refresh(object $document)

Refreshes a managed document.

object|null
load(mixed $criteria, object $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.

bool
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.

array
prepareProjection(array $fields)

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

array
prepareSort(array $fields)

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

string
prepareFieldName(string $fieldName)

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

array
addDiscriminatorToPreparedQuery(array $preparedQuery)

Adds discriminator criteria to an already-prepared query.

array
addFilterToPreparedQuery(array $preparedQuery)

Adds filter criteria to an already-prepared query.

array
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)

Initializes this instance.

Parameters

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

array getInserts()

Return Value

array

bool isQueuedForInsert(object $document)

Parameters

object $document

Return Value

bool

addInsert(object $document)

Adds a document to the queued insertions.

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

Parameters

object $document The document to queue for insertion.

array getUpserts()

Return Value

array

bool isQueuedForUpsert(object $document)

Parameters

object $document

Return Value

bool

addUpsert(object $document)

Adds a document to the queued upserts.

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

Parameters

object $document The document to queue for insertion.

ClassMetadata getClassMetadata()

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

Return Value

ClassMetadata

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 Options for batchInsert() and update() driver methods

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 Options for batchInsert() and update() driver methods

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

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

Parameters

object $document
array $options Array of options to be used with update()

Exceptions

LockException

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

Removes document from mongo

Parameters

mixed $document
array $options Array of options to be used with remove()

Exceptions

LockException

refresh(object $document)

Refreshes a managed document.

Parameters

object $document The document to refresh.

object|null load(mixed $criteria, object $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

mixed $criteria Query criteria
object $document Document to load the data into. If not specified, a new document is created.
array $hints Hints for document creation
int $lockMode
array|null $sort Sort array for Cursor::sort()

Return Value

object|null The loaded and managed document instance or null if no document was found

Exceptions

LockException

Iterator 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 Query criteria
array|null $sort Sort array for Cursor::sort()
int|null $limit Limit for Cursor::limit()
int|null $skip Skip for Cursor::skip()

Return Value

Iterator

bool exists(object $document)

Checks whether the given managed document exists in the database.

Parameters

object $document

Return Value

bool TRUE if the document exists in the database, FALSE otherwise.

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

Query createReferenceManyInverseSideQuery(PersistentCollectionInterface $collection)

Parameters

PersistentCollectionInterface $collection

Return Value

Query

Iterator createReferenceManyWithRepositoryMethodCursor(PersistentCollectionInterface $collection)

Parameters

PersistentCollectionInterface $collection

Return Value

Iterator

array prepareProjection(array $fields)

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

Parameters

array $fields

Return Value

array

array prepareSort(array $fields)

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

Parameters

array $fields

Return Value

array

string prepareFieldName(string $fieldName)

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

Parameters

string $fieldName

Return Value

string

array 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

Return Value

array

array 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

Return Value

array

array 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

Return Value

array