class PersistentCollection implements Collection (View source)

A PersistentCollection represents a collection of elements that have persistent state.

Methods

__construct(Collection $coll, DocumentManager $dm, UnitOfWork $uow)

No description

setDocumentManager(DocumentManager $dm)

Sets the document manager and unit of work (used during merge operations).

setMongoData(array $mongoData)

Sets the array of raw mongo data that will be used to initialize this collection.

array
getMongoData()

Gets the array of raw mongo data that will be used to initialize this collection.

setHints(array $hints)

Set hints to account for during reconstitution/lookup of the documents.

array
getHints()

Get hints to account for during reconstitution/lookup of the documents.

initialize()

Initializes the collection by loading its contents from the database if the collection is not yet initialized.

boolean
isDirty()

Gets a boolean flag indicating whether this collection is dirty which means its state needs to be synchronized with the database.

setDirty(boolean $dirty)

Sets a boolean flag, indicating whether this collection is dirty.

setOwner(object $document, array $mapping)

INTERNAL: Sets the collection's owning entity together with the AssociationMapping that describes the association between the owner and the elements of the collection.

takeSnapshot()

INTERNAL: Tells this collection to take a snapshot of its current state reindexing itself numerically if using save strategy that is enforcing BSON array.

clearSnapshot()

INTERNAL: Clears the internal snapshot information and sets isDirty to true if the collection has elements.

array
getSnapshot()

INTERNAL: Returns the last snapshot of the elements in the collection.

array
getDeleteDiff()

INTERNAL: getDeleteDiff

array
getDeletedDocuments()

INTERNAL: get objects that were removed, unlike getDeleteDiff this doesn't care about indices.

array
getInsertDiff()

INTERNAL: getInsertDiff

object
getOwner()

INTERNAL: Gets the collection owner.

array
getMapping()

No description

getTypeClass()

No description

setInitialized(boolean $bool)

Sets the initialized flag of the collection, forcing it into that state.

boolean
isInitialized()

Checks whether this collection has been initialized.

first()

{@inheritdoc}

last()

{@inheritdoc}

remove($key)

{@inheritdoc}

removeElement($element)

{@inheritdoc}

containsKey($key)

{@inheritdoc}

contains($element)

{@inheritdoc}

exists(Closure $p)

{@inheritdoc}

indexOf($element)

{@inheritdoc}

get($key)

{@inheritdoc}

getKeys()

{@inheritdoc}

getValues()

{@inheritdoc}

count()

{@inheritdoc}

set($key, $value)

{@inheritdoc}

add($value)

{@inheritdoc}

isEmpty()

{@inheritdoc}

getIterator()

{@inheritdoc}

map(Closure $func)

{@inheritdoc}

filter(Closure $p)

{@inheritdoc}

forAll(Closure $p)

{@inheritdoc}

partition(Closure $p)

{@inheritdoc}

toArray()

{@inheritdoc}

clear()

{@inheritdoc}

slice($offset, $length = null)

{@inheritdoc}

__sleep()

Called by PHP when this collection is serialized. Ensures that only the elements are properly serialized.

offsetExists($offset)

No description

offsetGet($offset)

No description

offsetSet($offset, $value)

No description

offsetUnset($offset)

No description

key()

No description

current()

Gets the element of the collection at the current iterator position.

next()

Moves the internal iterator position to the next element.

unwrap()

Retrieves the wrapped Collection instance.

__clone()

Cleanup internal state of cloned persistent collection.

Details

__construct(Collection $coll, DocumentManager $dm, UnitOfWork $uow)

Parameters

Collection $coll
DocumentManager $dm
UnitOfWork $uow

setDocumentManager(DocumentManager $dm)

Sets the document manager and unit of work (used during merge operations).

Parameters

DocumentManager $dm

setMongoData(array $mongoData)

Sets the array of raw mongo data that will be used to initialize this collection.

Parameters

array $mongoData

array getMongoData()

Gets the array of raw mongo data that will be used to initialize this collection.

Return Value

array $mongoData

setHints(array $hints)

Set hints to account for during reconstitution/lookup of the documents.

Parameters

array $hints

array getHints()

Get hints to account for during reconstitution/lookup of the documents.

Return Value

array $hints

initialize()

Initializes the collection by loading its contents from the database if the collection is not yet initialized.

boolean isDirty()

Gets a boolean flag indicating whether this collection is dirty which means its state needs to be synchronized with the database.

Return Value

boolean TRUE if the collection is dirty, FALSE otherwise.

setDirty(boolean $dirty)

Sets a boolean flag, indicating whether this collection is dirty.

Parameters

boolean $dirty Whether the collection should be marked dirty or not.

setOwner(object $document, array $mapping)

INTERNAL: Sets the collection's owning entity together with the AssociationMapping that describes the association between the owner and the elements of the collection.

Parameters

object $document
array $mapping

takeSnapshot()

INTERNAL: Tells this collection to take a snapshot of its current state reindexing itself numerically if using save strategy that is enforcing BSON array.

Reindexing is safe as snapshot is taken only after synchronizing collection with database or clearing it.

clearSnapshot()

INTERNAL: Clears the internal snapshot information and sets isDirty to true if the collection has elements.

array getSnapshot()

INTERNAL: Returns the last snapshot of the elements in the collection.

Return Value

array The last snapshot of the elements.

array getDeleteDiff()

INTERNAL: getDeleteDiff

Return Value

array

array getDeletedDocuments()

INTERNAL: get objects that were removed, unlike getDeleteDiff this doesn't care about indices.

Return Value

array

array getInsertDiff()

INTERNAL: getInsertDiff

Return Value

array

object getOwner()

INTERNAL: Gets the collection owner.

Return Value

object

array getMapping()

Return Value

array

ClassMetadata getTypeClass()

Return Value

ClassMetadata

Exceptions

MongoDBException

setInitialized(boolean $bool)

Sets the initialized flag of the collection, forcing it into that state.

Parameters

boolean $bool

boolean isInitialized()

Checks whether this collection has been initialized.

Return Value

boolean

first()

{@inheritdoc}

last()

{@inheritdoc}

remove($key)

{@inheritdoc}

Parameters

$key

removeElement($element)

{@inheritdoc}

Parameters

$element

containsKey($key)

{@inheritdoc}

Parameters

$key

contains($element)

{@inheritdoc}

Parameters

$element

exists(Closure $p)

{@inheritdoc}

Parameters

Closure $p

indexOf($element)

{@inheritdoc}

Parameters

$element

get($key)

{@inheritdoc}

Parameters

$key

getKeys()

{@inheritdoc}

getValues()

{@inheritdoc}

count()

{@inheritdoc}

set($key, $value)

{@inheritdoc}

Parameters

$key
$value

add($value)

{@inheritdoc}

Parameters

$value

isEmpty()

{@inheritdoc}

getIterator()

{@inheritdoc}

map(Closure $func)

{@inheritdoc}

Parameters

Closure $func

filter(Closure $p)

{@inheritdoc}

Parameters

Closure $p

forAll(Closure $p)

{@inheritdoc}

Parameters

Closure $p

partition(Closure $p)

{@inheritdoc}

Parameters

Closure $p

toArray()

{@inheritdoc}

clear()

{@inheritdoc}

slice($offset, $length = null)

{@inheritdoc}

Parameters

$offset
$length

__sleep()

Called by PHP when this collection is serialized. Ensures that only the elements are properly serialized.

offsetExists($offset)

Parameters

$offset

See also

containsKey()

offsetGet($offset)

Parameters

$offset

See also

get()

offsetSet($offset, $value)

Parameters

$offset
$value

See also

add()
set()

offsetUnset($offset)

Parameters

$offset

See also

remove()

key()

current()

Gets the element of the collection at the current iterator position.

next()

Moves the internal iterator position to the next element.

unwrap()

Retrieves the wrapped Collection instance.

__clone()

Cleanup internal state of cloned persistent collection.

The following problems have to be prevented: 1. Added documents are added to old PersistentCollection 2. New collection is not dirty, if reused on other document nothing changes. 3. Snapshot leads to invalid diffs being generated. 4. Lazy loading grabs entities from old owner object. 5. New collection is connected to old owner and leads to duplicate keys.