class PersistenceBuilder (View source)

PersistenceBuilder builds the queries used by the persisters to update and insert documents when a DocumentManager is flushed. It uses the changeset information in the UnitOfWork to build queries using atomic operators like $set, $unset, etc.

Methods

__construct(DocumentManager $dm, UnitOfWork $uow)

Initializes a new PersistenceBuilder instance.

array
prepareInsertData(object $document)

Prepares the array that is ready to be inserted to mongodb for a given object document.

array
prepareUpdateData(object $document)

Prepares the update query to update a given document object in mongodb.

array
prepareUpsertData(object $document)

Prepares the update query to upsert a given document object in mongodb.

array|null
prepareReferencedDocumentValue(array $referenceMapping, object $document)

Returns the reference representation to be stored in MongoDB.

array|object
prepareEmbeddedDocumentValue(array $embeddedMapping, object $embeddedDocument, bool $includeNestedCollections = false)

Returns the embedded document to be stored in MongoDB.

array|object|null
prepareAssociatedDocumentValue(array $mapping, object $document, bool $includeNestedCollections = false)

Returns the embedded document or reference representation to be stored.

array
prepareAssociatedCollectionValue(PersistentCollectionInterface $coll, $includeNestedCollections = false)

Returns the collection representation to be stored and unschedules it afterwards.

Details

__construct(DocumentManager $dm, UnitOfWork $uow)

Initializes a new PersistenceBuilder instance.

Parameters

DocumentManager $dm
UnitOfWork $uow

array prepareInsertData(object $document)

Prepares the array that is ready to be inserted to mongodb for a given object document.

Parameters

object $document

Return Value

array $insertData

array prepareUpdateData(object $document)

Prepares the update query to update a given document object in mongodb.

Parameters

object $document

Return Value

array $updateData

array prepareUpsertData(object $document)

Prepares the update query to upsert a given document object in mongodb.

Parameters

object $document

Return Value

array $updateData

array|null prepareReferencedDocumentValue(array $referenceMapping, object $document)

Returns the reference representation to be stored in MongoDB.

If the document does not have an identifier and the mapping calls for a simple reference, null may be returned.

Parameters

array $referenceMapping
object $document

Return Value

array|null

array|object prepareEmbeddedDocumentValue(array $embeddedMapping, object $embeddedDocument, bool $includeNestedCollections = false)

Returns the embedded document to be stored in MongoDB.

The return value will usually be an associative array with string keys corresponding to field names on the embedded document. An object may be returned if the document is empty, to ensure that a BSON object will be stored in lieu of an array.

If $includeNestedCollections is true, nested collections will be included in this prepared value and the option will cascade to all embedded associations. If any nested PersistentCollections (embed or reference) within this value were previously scheduled for deletion or update, they will also be unscheduled.

Parameters

array $embeddedMapping
object $embeddedDocument
bool $includeNestedCollections

Return Value

array|object

Exceptions

UnexpectedValueException If an unsupported associating mapping is found.

array|object|null prepareAssociatedDocumentValue(array $mapping, object $document, bool $includeNestedCollections = false)

Returns the embedded document or reference representation to be stored.

Parameters

array $mapping
object $document
bool $includeNestedCollections

Return Value

array|object|null

Exceptions

InvalidArgumentException If the mapping is neither embedded nor reference.

array prepareAssociatedCollectionValue(PersistentCollectionInterface $coll, $includeNestedCollections = false)

Returns the collection representation to be stored and unschedules it afterwards.

Parameters

PersistentCollectionInterface $coll
$includeNestedCollections

Return Value

array