class PersistentCollection implements Collection, Selectable (View source)

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

Collections of entities represent only the associations (links) to those entities. That means, if the collection is part of a many-many mapping and you remove entities from the collection, only the links in the relation table are removed (on flush). Similarly, if you remove entities from a collection that is part of a one-many mapping this will only result in the nulling out of the foreign keys on flush.

Methods

__construct(EntityManager $em, ClassMetadata $class, array $coll)

Creates a new persistent collection.

void
setOwner(object $entity, array $assoc)

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

object
getOwner()

INTERNAL: Gets the collection owner.

getTypeClass()

No description

void
hydrateAdd(mixed $element)

INTERNAL: Adds an element to a collection during hydration. This will automatically complete bidirectional associations in the case of a one-to-many association.

void
hydrateSet(mixed $key, mixed $element)

INTERNAL: Sets a keyed element in the collection during hydration.

void
initialize()

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

void
takeSnapshot()

INTERNAL: Tells this collection to take a snapshot of its current state.

array
getSnapshot()

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

array
getDeleteDiff()

INTERNAL: getDeleteDiff

array
getInsertDiff()

INTERNAL: getInsertDiff

array
getMapping()

INTERNAL: Gets the association mapping of the collection.

boolean
isDirty()

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

void
setDirty(boolean $dirty)

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

void
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}

array
__sleep()

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

offsetExists($offset)

{@inheritdoc}

offsetGet($offset)

{@inheritdoc}

offsetSet($offset, $value)

{@inheritdoc}

offsetUnset($offset)

{@inheritdoc}

key()

{@inheritdoc}

current()

{@inheritdoc}

next()

{@inheritdoc}

Collection
unwrap()

Retrieves the wrapped Collection instance.

array
slice(int $offset, int|null $length = null)

Extracts a slice of $length elements starting at position $offset from the Collection.

void
__clone()

Cleans up internal state of cloned persistent collection.

Collection
matching(Criteria $criteria)

Selects all elements from a selectable that match the expression and return a new collection containing these elements.

Details

__construct(EntityManager $em, ClassMetadata $class, array $coll)

Creates a new persistent collection.

Parameters

EntityManager $em The EntityManager the collection will be associated with.
ClassMetadata $class The class descriptor of the entity type of this collection.
array $coll The collection elements.

void setOwner(object $entity, array $assoc)

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 $entity
array $assoc

Return Value

void

object getOwner()

INTERNAL: Gets the collection owner.

Return Value

object

ClassMetadata getTypeClass()

Return Value

ClassMetadata

void hydrateAdd(mixed $element)

INTERNAL: Adds an element to a collection during hydration. This will automatically complete bidirectional associations in the case of a one-to-many association.

Parameters

mixed $element The element to add.

Return Value

void

void hydrateSet(mixed $key, mixed $element)

INTERNAL: Sets a keyed element in the collection during hydration.

Parameters

mixed $key The key to set.
mixed $element The element to set.

Return Value

void

void initialize()

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

Return Value

void

void takeSnapshot()

INTERNAL: Tells this collection to take a snapshot of its current state.

Return Value

void

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 getInsertDiff()

INTERNAL: getInsertDiff

Return Value

array

array getMapping()

INTERNAL: Gets the association mapping of the collection.

Return Value

array

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.

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

Return Value

void

void setInitialized(boolean $bool)

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

Parameters

boolean $bool

Return Value

void

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}

array __sleep()

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

Return Value

array

offsetExists($offset)

{@inheritdoc}

Parameters

$offset

offsetGet($offset)

{@inheritdoc}

Parameters

$offset

offsetSet($offset, $value)

{@inheritdoc}

Parameters

$offset
$value

offsetUnset($offset)

{@inheritdoc}

Parameters

$offset

key()

{@inheritdoc}

current()

{@inheritdoc}

next()

{@inheritdoc}

Collection unwrap()

Retrieves the wrapped Collection instance.

Return Value

Collection

array slice(int $offset, int|null $length = null)

Extracts a slice of $length elements starting at position $offset from the Collection.

If $length is null it returns all elements from $offset to the end of the Collection. Keys have to be preserved by this method. Calling this method will only return the selected slice and NOT change the elements contained in the collection slice is called on.

Parameters

int $offset
int|null $length

Return Value

array

void __clone()

Cleans up internal state of cloned persistent collection.

The following problems have to be prevented: 1. Added entities are added to old PC 2. New collection is not dirty, if reused on other entity 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.

Return Value

void

Collection matching(Criteria $criteria)

Selects all elements from a selectable that match the expression and return a new collection containing these elements.

Parameters

Criteria $criteria

Return Value

Collection

Exceptions

RuntimeException