PersistentCollection
class PersistentCollection extends AbstractLazyCollection implements 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
Creates a new persistent collection.
INTERNAL: Sets the collection's owning entity together with the AssociationMapping that describes the association between the owner and the elements of the collection.
INTERNAL: Gets the collection owner.
No description
INTERNAL: Adds an element to a collection during hydration. This will automatically complete bidirectional associations in the case of a one-to-many association.
INTERNAL: Sets a keyed element in the collection during hydration.
Initializes the collection by loading its contents from the database if the collection is not yet initialized.
INTERNAL: Tells this collection to take a snapshot of its current state.
INTERNAL: Returns the last snapshot of the elements in the collection.
INTERNAL: getDeleteDiff
INTERNAL: getInsertDiff
INTERNAL: Gets the association mapping of the collection.
Gets a boolean flag indicating whether this collection is dirty which means its state needs to be synchronized with the database.
Sets a boolean flag, indicating whether this collection is dirty.
Sets the initialized flag of the collection, forcing it into that state.
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
Called by PHP when this collection is serialized. Ensures that only the elements are properly serialized.
Extracts a slice of $length elements starting at position $offset from the Collection.
Cleans up internal state of cloned persistent collection.
Selects all elements from a selectable that match the expression and return a new collection containing these elements.
Retrieves the wrapped Collection instance.
{@inheritdoc}
Details
at line 100
__construct(EntityManagerInterface $em, ClassMetadata $class, Collection $collection)
Creates a new persistent collection.
at line 115
setOwner($entity, ToManyAssociationMetadata $association)
INTERNAL: Sets the collection's owning entity together with the AssociationMapping that describes the association between the owner and the elements of the collection.
at line 128
object
getOwner()
INTERNAL: Gets the collection owner.
at line 136
ClassMetadata
getTypeClass()
at line 148
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.
at line 175
hydrateSet(mixed $key, mixed $element)
INTERNAL: Sets a keyed element in the collection during hydration.
at line 199
initialize()
Initializes the collection by loading its contents from the database if the collection is not yet initialized.
at line 214
takeSnapshot()
INTERNAL: Tells this collection to take a snapshot of its current state.
at line 226
object[]
getSnapshot()
INTERNAL: Returns the last snapshot of the elements in the collection.
at line 237
object[]
getDeleteDiff()
INTERNAL: getDeleteDiff
at line 253
object[]
getInsertDiff()
INTERNAL: getInsertDiff
at line 268
AssociationMetadata
getMapping()
INTERNAL: Gets the association mapping of the collection.
at line 298
bool
isDirty()
Gets a boolean flag indicating whether this collection is dirty which means its state needs to be synchronized with the database.
at line 308
setDirty(bool $dirty)
Sets a boolean flag, indicating whether this collection is dirty.
at line 318
setInitialized(bool $bool)
Sets the initialized flag of the collection, forcing it into that state.
at line 326
remove($key)
{@inheritdoc}
at line 353
removeElement($element)
{@inheritdoc}
at line 388
containsKey($key)
{@inheritdoc}
at line 405
contains($element)
{@inheritdoc}
at line 421
get($key)
{@inheritdoc}
at line 440
count()
{@inheritdoc}
at line 456
set($key, $value)
{@inheritdoc}
at line 470
add($value)
{@inheritdoc}
at line 488
offsetExists($offset)
{@inheritdoc}
at line 496
offsetGet($offset)
{@inheritdoc}
at line 504
offsetSet($offset, $value)
{@inheritdoc}
at line 517
offsetUnset($offset)
{@inheritdoc}
at line 525
isEmpty()
{@inheritdoc}
at line 537
clear()
{@inheritdoc}
at line 581
string[]
__sleep()
Called by PHP when this collection is serialized. Ensures that only the elements are properly serialized.
{@internal Tried to implement Serializable first but that did not work well with circular references. This solution seems simpler and works well. }}
at line 598
object[]
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.
at line 623
__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.
at line 645
Collection|object[]
matching(Criteria $criteria)
Selects all elements from a selectable that match the expression and return a new collection containing these elements.
at line 681
Collection|object[]
unwrap()
Retrieves the wrapped Collection instance.
at line 689
protected
doInitialize()
{@inheritdoc}