UnitOfWork
in package
implements
PropertyChangedListener
The UnitOfWork is responsible for tracking changes to objects during an "object-level" transaction and for writing out changes to the database in the correct order.
Internal note: This class contains highly performance-sensitive code.
Tags
Table of Contents
Interfaces
- PropertyChangedListener
- Contract for classes that are potential listeners of a {@see NotifyPropertyChanged} implementor.
Constants
- HINT_DEFEREAGERLOAD = 'deferEagerLoad'
- Hint used to collect all primary keys of associated entities during hydration and execute it in a dedicated query afterwards
- STATE_DETACHED = 3
- A detached entity is an instance with persistent state and identity that is not (or no longer) associated with an EntityManager (and a UnitOfWork).
- STATE_MANAGED = 1
- An entity is in MANAGED state when its persistence is managed by an EntityManager.
- STATE_NEW = 2
- An entity is new if it has just been instantiated (i.e. using the "new" operator) and is not (yet) managed by an EntityManager.
- STATE_REMOVED = 4
- A removed entity instance is an instance with a persistent identity, associated with an EntityManager, whose persistent state will be deleted on commit.
Properties
- $hasCache : bool
- $collectionDeletions : mixed
- All pending collection deletions.
- $collectionPersisters : mixed
- The collection persister instances used to persist collections.
- $collectionUpdates : mixed
- All pending collection updates.
- $eagerLoadingEntities : mixed
- Map of Entity Class-Names and corresponding IDs that should eager loaded when requested.
- $em : EntityManagerInterface
- The EntityManager that "owns" this UnitOfWork instance.
- $entityChangeSets : mixed
- Map of entity changes. Keys are object ids (spl_object_id).
- $entityDeletions : mixed
- A list of all pending entity deletions.
- $entityIdentifiers : array<string|int, mixed>
- Map of all identifiers of managed entities.
- $entityInsertions : mixed
- A list of all pending entity insertions.
- $entityStates : mixed
- The (cached) states of any known entities.
- $entityUpdates : mixed
- A list of all pending entity updates.
- $evm : EventManager
- The EventManager used for dispatching events.
- $extraUpdates : mixed
- Any pending extra updates that have been scheduled by persisters.
- $hydrationCompleteHandler : HydrationCompleteHandler
- Helper for handling completion of hydration
- $identifierFlattener : IdentifierFlattener
- The IdentifierFlattener used for manipulating identifiers
- $identityMap : array<string|int, mixed>
- The identity map that holds references to all managed entities that have an identity. The entities are grouped by their class name.
- $listenersInvoker : ListenersInvoker
- The ListenersInvoker used for dispatching events.
- $nonCascadedNewDetectedEntities : array<int, AssociationMapping, : object}>
- New entities that were discovered through relationships that were not marked as cascade-persist. During flush, this array is populated and then pruned of any entities that were discovered through a valid cascade-persist path. (Leftovers cause an error.)
- $originalEntityData : mixed
- Map of the original entity data of managed entities.
- $orphanRemovals : mixed
- Orphaned entities that are scheduled for removal.
- $persisters : mixed
- The entity persister instances used to persist entity instances.
- $readOnlyObjects : array<int, true>
- Read-Only objects are never evaluated
- $reflectionPropertiesGetter : ReflectionPropertiesGetter
- $scheduledForSynchronization : mixed
- Map of entities that are scheduled for dirty checking at commit time.
- $visitedCollections : mixed
- List of collections visited during changeset calculation on a commit-phase of a UnitOfWork.
Methods
- __construct() : mixed
- Initializes a new UnitOfWork instance, bound to the given EntityManager.
- clear() : void
- Clears the UnitOfWork.
- clearEntityChangeSet() : void
- INTERNAL: Clears the property changeset of the entity with the given OID.
- commit() : void
- Commits the UnitOfWork, executing all operations that have been postponed up to this point. The state of all managed entities will be synchronized with the database.
- computeChangeSets() : void
- Computes all the changes that have been done to entities and collections since the last commit and stores these changes in the _entityChangeSet map temporarily for access by the persisters, until the UoW commit is finished.
- detach() : void
- Detaches an entity from the persistence management. It's persistence will no longer be managed by Doctrine.
- getCollectionPersister() : CollectionPersister
- Gets a collection persister for a collection-valued association.
- getCommitOrderCalculator() : CommitOrderCalculator
- Gets the CommitOrderCalculator used by the UnitOfWork to order commits.
- getEntityChangeSet() : array<string|int, array<string|int, mixed>>
- Gets the changeset for an entity.
- getEntityIdentifier() : array<string|int, mixed>
- Gets the identifier of an entity.
- getEntityPersister() : EntityPersister
- Gets the EntityPersister for an Entity.
- getEntityState() : int
- Gets the state of an entity with regard to the current unit of work.
- getIdentityMap() : mixed
- Gets the identity map of the UnitOfWork.
- getIdHashByEntity() : string
- Gets the id hash of an entity.
- getIdHashByIdentifier() : string
- Gets the id hash of an entity by its identifier.
- getOriginalEntityData() : array<string|int, mixed>
- Gets the original data of an entity. The original data is the data that was present at the time the entity was reconstituted from the database.
- getScheduledCollectionDeletions() : mixed
- Gets the currently scheduled complete collection deletions
- getScheduledCollectionUpdates() : mixed
- Gets the currently scheduled collection inserts, updates and deletes.
- getScheduledEntityDeletions() : mixed
- Gets the currently scheduled entity deletions in this UnitOfWork.
- getScheduledEntityInsertions() : mixed
- Gets the currently scheduled entity insertions in this UnitOfWork.
- getScheduledEntityUpdates() : mixed
- Gets the currently scheduled entity updates in this UnitOfWork.
- getSingleIdentifierValue() : mixed
- Processes an entity instance to extract their identifier values.
- hasPendingInsertions() : bool
- Checks whether the UnitOfWork has any pending insertions.
- initializeObject() : void
- Helper method to initialize a lazy loading proxy or persistent collection.
- isCollectionScheduledForDeletion() : bool
- isEntityScheduled() : bool
- Checks whether an entity is scheduled for insertion, update or deletion.
- isInIdentityMap() : bool
- Checks whether an entity is registered in the identity map of this UnitOfWork.
- isReadOnly() : bool
- Is this entity read only?
- isScheduledForDelete() : bool
- Checks whether an entity is registered as removed/deleted with the unit of work.
- isScheduledForDirtyCheck() : bool
- Checks whether an entity is registered to be checked in the unit of work.
- isScheduledForInsert() : bool
- Checks whether an entity is scheduled for insertion.
- isScheduledForUpdate() : bool
- Checks whether an entity is registered as dirty in the unit of work.
- loadCollection() : void
- Initializes (loads) an uninitialized persistent collection of an entity.
- lock() : void
- Acquire a lock on the given entity.
- markReadOnly() : void
- Marks an entity as read-only so that it will not be considered for updates during UnitOfWork#commit().
- merge() : object
- Merges the state of the given detached entity into this UnitOfWork.
- persist() : void
- Persists an entity as part of the current unit of work.
- propertyChanged() : void
- Notifies this UnitOfWork of a property change in an entity.
- refresh() : void
- Refreshes the state of the given entity from the database, overwriting any local, unpersisted changes.
- registerManaged() : void
- INTERNAL: Registers an entity as managed.
- remove() : void
- Deletes an entity as part of the current unit of work.
- scheduleCollectionDeletion() : void
- INTERNAL: Schedules a complete collection for removal when this UnitOfWork commits.
- scheduleForDelete() : void
- INTERNAL: Schedules an entity for deletion.
- scheduleForDirtyCheck() : void
- Schedules an entity for dirty-checking at commit-time.
- scheduleForInsert() : void
- Schedules an entity for insertion into the database.
- scheduleForUpdate() : void
- Schedules an entity for being updated.
- size() : int
- Calculates the size of the UnitOfWork. The size of the UnitOfWork is the number of entities in the identity map.
- triggerEagerLoads() : void
- tryGetById() : object|false
- Tries to find an entity with the given identifier in the identity map of this UnitOfWork.
- addToEntityIdentifiersAndEntityMap() : void
- afterTransactionComplete() : void
- Perform whatever processing is encapsulated here after completion of the transaction.
- afterTransactionRolledBack() : void
- Perform whatever processing is encapsulated here after completion of the rolled-back.
- assertThatThereAreNoUnintentionallyNonPersistedAssociations() : void
- cascadeDetach() : void
- Cascades a detach operation to associated entities.
- cascadeMerge() : void
- Cascades a merge operation to associated entities.
- cascadePersist() : void
- Cascades the save operation to associated entities.
- cascadeRefresh() : void
- Cascades a refresh operation to associated entities.
- cascadeRemove() : void
- Cascades the delete operation to associated entities.
- clearEntityInsertionsForEntityName() : void
- clearIdentityMapForEntityName() : void
- computeAssociationChanges() : void
- Computes the changes of an association.
- computeScheduleInsertsChangeSets() : void
- Computes the changesets of all entities scheduled for insertion.
- computeSingleEntityChangeSet() : void
- Only flushes the given entity according to a ruleset that keeps the UoW consistent.
- convertSingleFieldIdentifierToPHPValue() : mixed
- dispatchOnFlushEvent() : void
- dispatchPostFlushEvent() : void
- doDetach() : void
- Executes a detach operation on the given entity.
- doMerge() : object
- Executes a merge operation on an entity.
- doPersist() : void
- Persists an entity as part of the current unit of work.
- doRefresh() : void
- Executes a refresh operation on an entity.
- doRemove() : void
- Deletes an entity as part of the current unit of work.
- ensureVersionMatch() : void
- executeDeletions() : void
- Executes all entity deletions for entities of the specified type.
- executeExtraUpdates() : void
- Executes any extra updates that have been scheduled.
- executeInserts() : void
- Executes all entity insertions for entities of the specified type.
- executeUpdates() : void
- Executes all entity updates for entities of the specified type.
- getCommitOrder() : array<int, ClassMetadata>
- Gets the commit order.
- hasMissingIdsWhichAreForeignKeys() : bool
- isIdentifierEquals() : bool
- Verifies if two given entities actually are the same based on identifier comparison
- isLoaded() : bool
- Tests if an entity is loaded - must either be a loaded proxy or not a proxy
- mergeEntityStateIntoManagedCopy() : void
- newInstance() : object
- normalizeIdentifier() : array<string, mixed>
- Given a flat identifier, this method will produce another flat identifier, but with all association fields that are mapped as identifiers replaced by entity references, recursively.
- objToStr() : string
- Helper method to show an object as string.
- performCallbackOnCachedPersister() : void
- Performs an action after the transaction.
- persistNew() : void
- postCommitCleanup() : void
- updateAssociationWithMergedEntity() : void
- Sets/adds associated managed copies into the previous entity's association field
Constants
HINT_DEFEREAGERLOAD
Hint used to collect all primary keys of associated entities during hydration and execute it in a dedicated query afterwards
public
mixed
HINT_DEFEREAGERLOAD
= 'deferEagerLoad'
Tags
STATE_DETACHED
A detached entity is an instance with persistent state and identity that is not (or no longer) associated with an EntityManager (and a UnitOfWork).
public
mixed
STATE_DETACHED
= 3
STATE_MANAGED
An entity is in MANAGED state when its persistence is managed by an EntityManager.
public
mixed
STATE_MANAGED
= 1
STATE_NEW
An entity is new if it has just been instantiated (i.e. using the "new" operator) and is not (yet) managed by an EntityManager.
public
mixed
STATE_NEW
= 2
STATE_REMOVED
A removed entity instance is an instance with a persistent identity, associated with an EntityManager, whose persistent state will be deleted on commit.
public
mixed
STATE_REMOVED
= 4
Properties
$hasCache
protected
bool
$hasCache
= false
$collectionDeletions
All pending collection deletions.
private
mixed
$collectionDeletions
= []
Tags
$collectionPersisters
The collection persister instances used to persist collections.
private
mixed
$collectionPersisters
= []
Tags
$collectionUpdates
All pending collection updates.
private
mixed
$collectionUpdates
= []
Tags
$eagerLoadingEntities
Map of Entity Class-Names and corresponding IDs that should eager loaded when requested.
private
mixed
$eagerLoadingEntities
= []
Tags
$em
The EntityManager that "owns" this UnitOfWork instance.
private
EntityManagerInterface
$em
$entityChangeSets
Map of entity changes. Keys are object ids (spl_object_id).
private
mixed
$entityChangeSets
= []
Filled at the beginning of a commit of the UnitOfWork and cleaned at the end.
Tags
$entityDeletions
A list of all pending entity deletions.
private
mixed
$entityDeletions
= []
Tags
$entityIdentifiers
Map of all identifiers of managed entities.
private
array<string|int, mixed>
$entityIdentifiers
= []
Keys are object ids (spl_object_id).
Tags
$entityInsertions
A list of all pending entity insertions.
private
mixed
$entityInsertions
= []
Tags
$entityStates
The (cached) states of any known entities.
private
mixed
$entityStates
= []
Keys are object ids (spl_object_id).
Tags
$entityUpdates
A list of all pending entity updates.
private
mixed
$entityUpdates
= []
Tags
$evm
The EventManager used for dispatching events.
private
EventManager
$evm
$extraUpdates
Any pending extra updates that have been scheduled by persisters.
private
mixed
$extraUpdates
= []
Tags
$hydrationCompleteHandler
Helper for handling completion of hydration
private
HydrationCompleteHandler
$hydrationCompleteHandler
$identifierFlattener
The IdentifierFlattener used for manipulating identifiers
private
IdentifierFlattener
$identifierFlattener
$identityMap
The identity map that holds references to all managed entities that have an identity. The entities are grouped by their class name.
private
array<string|int, mixed>
$identityMap
= []
Since all classes in a hierarchy must share the same identifier set, we always take the root class name of the hierarchy.
Tags
$listenersInvoker
The ListenersInvoker used for dispatching events.
private
ListenersInvoker
$listenersInvoker
$nonCascadedNewDetectedEntities
New entities that were discovered through relationships that were not marked as cascade-persist. During flush, this array is populated and then pruned of any entities that were discovered through a valid cascade-persist path. (Leftovers cause an error.)
private
array<int, AssociationMapping, : object}>
$nonCascadedNewDetectedEntities
= []
Keys are OIDs, payload is a two-item array describing the association and the entity.
indexed by respective object spl_object_id()
$originalEntityData
Map of the original entity data of managed entities.
private
mixed
$originalEntityData
= []
Keys are object ids (spl_object_id). This is used for calculating changesets at commit time.
Internal note: Note that PHPs "copy-on-write" behavior helps a lot with memory usage. A value will only really be copied if the value in the entity is modified by the user.
Tags
$orphanRemovals
Orphaned entities that are scheduled for removal.
private
mixed
$orphanRemovals
= []
Tags
$persisters
The entity persister instances used to persist entity instances.
private
mixed
$persisters
= []
Tags
$readOnlyObjects
Read-Only objects are never evaluated
private
array<int, true>
$readOnlyObjects
= []
$reflectionPropertiesGetter
private
ReflectionPropertiesGetter
$reflectionPropertiesGetter
$scheduledForSynchronization
Map of entities that are scheduled for dirty checking at commit time.
private
mixed
$scheduledForSynchronization
= []
This is only used for entities with a change tracking policy of DEFERRED_EXPLICIT. Keys are object ids (spl_object_id).
Tags
$visitedCollections
List of collections visited during changeset calculation on a commit-phase of a UnitOfWork.
private
mixed
$visitedCollections
= []
At the end of the UnitOfWork all these collections will make new snapshots of their data.
Tags
Methods
__construct()
Initializes a new UnitOfWork instance, bound to the given EntityManager.
public
__construct(EntityManagerInterface $em) : mixed
Parameters
- $em : EntityManagerInterface
clear()
Clears the UnitOfWork.
public
clear([string|null $entityName = null ]) : void
Parameters
- $entityName : string|null = null
-
if given, only entities of this type will get detached.
Tags
clearEntityChangeSet()
INTERNAL: Clears the property changeset of the entity with the given OID.
public
clearEntityChangeSet(int $oid) : void
Parameters
- $oid : int
-
The entity's OID.
commit()
Commits the UnitOfWork, executing all operations that have been postponed up to this point. The state of all managed entities will be synchronized with the database.
public
commit([object|array<string|int, mixed>|null $entity = null ]) : void
The operations are executed in the following order:
- All entity insertions
- All entity updates
- All collection deletions
- All collection updates
- All entity deletions
Parameters
- $entity : object|array<string|int, mixed>|null = null
Tags
computeChangeSets()
Computes all the changes that have been done to entities and collections since the last commit and stores these changes in the _entityChangeSet map temporarily for access by the persisters, until the UoW commit is finished.
public
computeChangeSets() : void
detach()
Detaches an entity from the persistence management. It's persistence will no longer be managed by Doctrine.
public
detach(object $entity) : void
Parameters
- $entity : object
-
The entity to detach.
getCollectionPersister()
Gets a collection persister for a collection-valued association.
public
getCollectionPersister(array<string|int, mixed> $association) : CollectionPersister
Parameters
- $association : array<string|int, mixed>
Tags
Return values
CollectionPersistergetCommitOrderCalculator()
Gets the CommitOrderCalculator used by the UnitOfWork to order commits.
public
getCommitOrderCalculator() : CommitOrderCalculator
Return values
CommitOrderCalculatorgetEntityChangeSet()
Gets the changeset for an entity.
public
& getEntityChangeSet(object $entity) : array<string|int, array<string|int, mixed>>
Parameters
- $entity : object
Tags
Return values
array<string|int, array<string|int, mixed>>getEntityIdentifier()
Gets the identifier of an entity.
public
getEntityIdentifier(object $entity) : array<string|int, mixed>
The returned value is always an array of identifier values. If the entity has a composite identifier then the identifier values are in the same order as the identifier field names as returned by ClassMetadata#getIdentifierFieldNames().
Parameters
- $entity : object
Return values
array<string|int, mixed> —The identifier values.
getEntityPersister()
Gets the EntityPersister for an Entity.
public
getEntityPersister(string $entityName) : EntityPersister
Parameters
- $entityName : string
-
The name of the Entity.
Tags
Return values
EntityPersistergetEntityState()
Gets the state of an entity with regard to the current unit of work.
public
getEntityState(object $entity[, int|null $assume = null ]) : int
Parameters
- $entity : object
- $assume : int|null = null
-
The state to assume if the state is not yet known (not MANAGED or REMOVED). This parameter can be set to improve performance of entity state detection by potentially avoiding a database lookup if the distinction between NEW and DETACHED is either known or does not matter for the caller of the method.
Tags
Return values
int —The entity state.
getIdentityMap()
Gets the identity map of the UnitOfWork.
public
getIdentityMap() : mixed
Tags
getIdHashByEntity()
Gets the id hash of an entity.
public
getIdHashByEntity(object $entity) : string
Parameters
- $entity : object
-
The entity managed by Unit Of Work
Return values
string —The entity id hash.
getIdHashByIdentifier()
Gets the id hash of an entity by its identifier.
public
final static getIdHashByIdentifier(array<string|int, mixed> $identifier) : string
Parameters
- $identifier : array<string|int, mixed>
-
The identifier of an entity
Return values
string —The entity id hash.
getOriginalEntityData()
Gets the original data of an entity. The original data is the data that was present at the time the entity was reconstituted from the database.
public
getOriginalEntityData(object $entity) : array<string|int, mixed>
Parameters
- $entity : object
Tags
Return values
array<string|int, mixed>getScheduledCollectionDeletions()
Gets the currently scheduled complete collection deletions
public
getScheduledCollectionDeletions() : mixed
Tags
getScheduledCollectionUpdates()
Gets the currently scheduled collection inserts, updates and deletes.
public
getScheduledCollectionUpdates() : mixed
Tags
getScheduledEntityDeletions()
Gets the currently scheduled entity deletions in this UnitOfWork.
public
getScheduledEntityDeletions() : mixed
Tags
getScheduledEntityInsertions()
Gets the currently scheduled entity insertions in this UnitOfWork.
public
getScheduledEntityInsertions() : mixed
Tags
getScheduledEntityUpdates()
Gets the currently scheduled entity updates in this UnitOfWork.
public
getScheduledEntityUpdates() : mixed
Tags
getSingleIdentifierValue()
Processes an entity instance to extract their identifier values.
public
getSingleIdentifierValue(object $entity) : mixed
Parameters
- $entity : object
-
The entity instance.
Tags
Return values
mixed —A scalar value.
hasPendingInsertions()
Checks whether the UnitOfWork has any pending insertions.
public
hasPendingInsertions() : bool
Return values
bool —TRUE if this UnitOfWork has pending insertions, FALSE otherwise.
initializeObject()
Helper method to initialize a lazy loading proxy or persistent collection.
public
initializeObject(object $obj) : void
Parameters
- $obj : object
isCollectionScheduledForDeletion()
public
isCollectionScheduledForDeletion(PersistentCollection $coll) : bool
Parameters
- $coll : PersistentCollection
Return values
boolisEntityScheduled()
Checks whether an entity is scheduled for insertion, update or deletion.
public
isEntityScheduled(object $entity) : bool
Parameters
- $entity : object
Return values
boolisInIdentityMap()
Checks whether an entity is registered in the identity map of this UnitOfWork.
public
isInIdentityMap(object $entity) : bool
Parameters
- $entity : object
Return values
boolisReadOnly()
Is this entity read only?
public
isReadOnly(object $object) : bool
Parameters
- $object : object
Tags
Return values
boolisScheduledForDelete()
Checks whether an entity is registered as removed/deleted with the unit of work.
public
isScheduledForDelete(object $entity) : bool
Parameters
- $entity : object
Return values
boolisScheduledForDirtyCheck()
Checks whether an entity is registered to be checked in the unit of work.
public
isScheduledForDirtyCheck(object $entity) : bool
Parameters
- $entity : object
Return values
boolisScheduledForInsert()
Checks whether an entity is scheduled for insertion.
public
isScheduledForInsert(object $entity) : bool
Parameters
- $entity : object
Return values
boolisScheduledForUpdate()
Checks whether an entity is registered as dirty in the unit of work.
public
isScheduledForUpdate(object $entity) : bool
Note: Is not very useful currently as dirty entities are only registered at commit time.
Parameters
- $entity : object
Return values
boolloadCollection()
Initializes (loads) an uninitialized persistent collection of an entity.
public
loadCollection(PersistentCollection $collection) : void
Parameters
- $collection : PersistentCollection
-
The collection to initialize.
Tags
lock()
Acquire a lock on the given entity.
public
lock(object $entity, int $lockMode[, int|DateTimeInterface|null $lockVersion = null ]) : void
Parameters
- $entity : object
- $lockMode : int
- $lockVersion : int|DateTimeInterface|null = null
Tags
markReadOnly()
Marks an entity as read-only so that it will not be considered for updates during UnitOfWork#commit().
public
markReadOnly(object $object) : void
This operation cannot be undone as some parts of the UnitOfWork now keep gathering information on this object that might be necessary to perform a correct update.
Parameters
- $object : object
Tags
merge()
Merges the state of the given detached entity into this UnitOfWork.
public
merge(object $entity) : object
Parameters
- $entity : object
Tags
Return values
object —The managed copy of the entity.
persist()
Persists an entity as part of the current unit of work.
public
persist(object $entity) : void
Parameters
- $entity : object
-
The entity to persist.
propertyChanged()
Notifies this UnitOfWork of a property change in an entity.
public
propertyChanged(object $sender, string $propertyName, mixed $oldValue, mixed $newValue) : void
Parameters
- $sender : object
-
The entity that owns the property.
- $propertyName : string
-
The name of the property that changed.
- $oldValue : mixed
-
The old value of the property.
- $newValue : mixed
-
The new value of the property.
refresh()
Refreshes the state of the given entity from the database, overwriting any local, unpersisted changes.
public
refresh(object $entity) : void
Parameters
- $entity : object
-
The entity to refresh
Tags
registerManaged()
INTERNAL: Registers an entity as managed.
public
registerManaged(object $entity, array<string|int, mixed> $id, array<string|int, mixed> $data) : void
Parameters
- $entity : object
-
The entity.
- $id : array<string|int, mixed>
-
The identifier values.
- $data : array<string|int, mixed>
-
The original entity data.
remove()
Deletes an entity as part of the current unit of work.
public
remove(object $entity) : void
Parameters
- $entity : object
-
The entity to remove.
scheduleCollectionDeletion()
INTERNAL: Schedules a complete collection for removal when this UnitOfWork commits.
public
scheduleCollectionDeletion(PersistentCollection $coll) : void
Parameters
- $coll : PersistentCollection
scheduleForDelete()
INTERNAL: Schedules an entity for deletion.
public
scheduleForDelete(object $entity) : void
Parameters
- $entity : object
scheduleForDirtyCheck()
Schedules an entity for dirty-checking at commit-time.
public
scheduleForDirtyCheck(object $entity) : void
Parameters
- $entity : object
-
The entity to schedule for dirty-checking.
Tags
scheduleForInsert()
Schedules an entity for insertion into the database.
public
scheduleForInsert(object $entity) : void
If the entity already has an identifier, it will be added to the identity map.
Parameters
- $entity : object
-
The entity to schedule for insertion.
Tags
scheduleForUpdate()
Schedules an entity for being updated.
public
scheduleForUpdate(object $entity) : void
Parameters
- $entity : object
-
The entity to schedule for being updated.
Tags
size()
Calculates the size of the UnitOfWork. The size of the UnitOfWork is the number of entities in the identity map.
public
size() : int
Return values
inttriggerEagerLoads()
public
triggerEagerLoads() : void
tryGetById()
Tries to find an entity with the given identifier in the identity map of this UnitOfWork.
public
tryGetById(mixed $id, string $rootClassName) : object|false
Parameters
- $id : mixed
-
The entity identifier to look for.
- $rootClassName : string
-
The name of the root class of the mapped entity hierarchy.
Tags
Return values
object|false —Returns the entity with the specified identifier if it exists in this UnitOfWork, FALSE otherwise.
addToEntityIdentifiersAndEntityMap()
private
addToEntityIdentifiersAndEntityMap(ClassMetadata $class, int $oid, object $entity) : void
Parameters
- $class : ClassMetadata
- $oid : int
- $entity : object
Tags
afterTransactionComplete()
Perform whatever processing is encapsulated here after completion of the transaction.
private
afterTransactionComplete() : void
afterTransactionRolledBack()
Perform whatever processing is encapsulated here after completion of the rolled-back.
private
afterTransactionRolledBack() : void
assertThatThereAreNoUnintentionallyNonPersistedAssociations()
private
assertThatThereAreNoUnintentionallyNonPersistedAssociations() : void
Tags
cascadeDetach()
Cascades a detach operation to associated entities.
private
cascadeDetach(object $entity, array<int, object> &$visited) : void
Parameters
- $entity : object
- $visited : array<int, object>
cascadeMerge()
Cascades a merge operation to associated entities.
private
cascadeMerge(object $entity, object $managedCopy, array<string|int, mixed> &$visited) : void
Parameters
- $entity : object
- $managedCopy : object
- $visited : array<string|int, mixed>
Tags
cascadePersist()
Cascades the save operation to associated entities.
private
cascadePersist(object $entity, array<string|int, mixed> &$visited) : void
Parameters
- $entity : object
- $visited : array<string|int, mixed>
Tags
cascadeRefresh()
Cascades a refresh operation to associated entities.
private
cascadeRefresh(object $entity, array<string|int, mixed> &$visited[, int|null $lockMode = null ]) : void
Parameters
- $entity : object
- $visited : array<string|int, mixed>
- $lockMode : int|null = null
Tags
cascadeRemove()
Cascades the delete operation to associated entities.
private
cascadeRemove(object $entity, array<string|int, mixed> &$visited) : void
Parameters
- $entity : object
- $visited : array<string|int, mixed>
Tags
clearEntityInsertionsForEntityName()
private
clearEntityInsertionsForEntityName(string $entityName) : void
Parameters
- $entityName : string
clearIdentityMapForEntityName()
private
clearIdentityMapForEntityName(string $entityName) : void
Parameters
- $entityName : string
computeAssociationChanges()
Computes the changes of an association.
private
computeAssociationChanges(array<string|int, mixed> $assoc, mixed $value) : void
Parameters
- $assoc : array<string|int, mixed>
- $value : mixed
-
The value of the association.
Tags
computeScheduleInsertsChangeSets()
Computes the changesets of all entities scheduled for insertion.
private
computeScheduleInsertsChangeSets() : void
computeSingleEntityChangeSet()
Only flushes the given entity according to a ruleset that keeps the UoW consistent.
private
computeSingleEntityChangeSet(object $entity) : void
- All entities scheduled for insertion, (orphan) removals and changes in collections are processed as well!
- Read Only entities are skipped.
- Proxies are skipped.
- Only if entity is properly managed.
Parameters
- $entity : object
Tags
convertSingleFieldIdentifierToPHPValue()
private
convertSingleFieldIdentifierToPHPValue(ClassMetadata $class, mixed $identifierValue) : mixed
Parameters
- $class : ClassMetadata
- $identifierValue : mixed
Tags
Return values
mixed —the identifier after type conversion
dispatchOnFlushEvent()
private
dispatchOnFlushEvent() : void
dispatchPostFlushEvent()
private
dispatchPostFlushEvent() : void
doDetach()
Executes a detach operation on the given entity.
private
doDetach(object $entity, array<string|int, mixed> &$visited[, bool $noCascade = false ]) : void
Parameters
- $entity : object
- $visited : array<string|int, mixed>
- $noCascade : bool = false
-
if true, don't cascade detach operation.
doMerge()
Executes a merge operation on an entity.
private
doMerge(object $entity, array<string|int, mixed> &$visited[, mixed $prevManagedCopy = null ][, array<string|int, mixed>|null $assoc = null ]) : object
Parameters
- $entity : object
- $visited : array<string|int, mixed>
- $prevManagedCopy : mixed = null
- $assoc : array<string|int, mixed>|null = null
Tags
Return values
object —The managed copy of the entity.
doPersist()
Persists an entity as part of the current unit of work.
private
doPersist(object $entity, array<string|int, mixed> &$visited) : void
This method is internally called during persist() cascades as it tracks the already visited entities to prevent infinite recursions.
Parameters
- $entity : object
-
The entity to persist.
- $visited : array<string|int, mixed>
Tags
doRefresh()
Executes a refresh operation on an entity.
private
doRefresh(object $entity, array<string|int, mixed> &$visited[, int|null $lockMode = null ]) : void
Parameters
- $entity : object
-
The entity to refresh.
- $visited : array<string|int, mixed>
- $lockMode : int|null = null
Tags
doRemove()
Deletes an entity as part of the current unit of work.
private
doRemove(object $entity, array<string|int, mixed> &$visited) : void
This method is internally called during delete() cascades as it tracks the already visited entities to prevent infinite recursions.
Parameters
- $entity : object
-
The entity to delete.
- $visited : array<string|int, mixed>
Tags
ensureVersionMatch()
private
ensureVersionMatch(ClassMetadata $class, object $entity, object $managedCopy) : void
Parameters
- $class : ClassMetadata
- $entity : object
- $managedCopy : object
Tags
executeDeletions()
Executes all entity deletions for entities of the specified type.
private
executeDeletions(ClassMetadata $class) : void
Parameters
- $class : ClassMetadata
executeExtraUpdates()
Executes any extra updates that have been scheduled.
private
executeExtraUpdates() : void
executeInserts()
Executes all entity insertions for entities of the specified type.
private
executeInserts(ClassMetadata $class) : void
Parameters
- $class : ClassMetadata
executeUpdates()
Executes all entity updates for entities of the specified type.
private
executeUpdates(ClassMetadata $class) : void
Parameters
- $class : ClassMetadata
getCommitOrder()
Gets the commit order.
private
getCommitOrder() : array<int, ClassMetadata>
Return values
array<int, ClassMetadata>hasMissingIdsWhichAreForeignKeys()
private
hasMissingIdsWhichAreForeignKeys(ClassMetadata $class, array<string|int, mixed> $idValue) : bool
Parameters
- $class : ClassMetadata
- $idValue : array<string|int, mixed>
Return values
boolisIdentifierEquals()
Verifies if two given entities actually are the same based on identifier comparison
private
isIdentifierEquals(object $entity1, object $entity2) : bool
Parameters
- $entity1 : object
- $entity2 : object
Return values
boolisLoaded()
Tests if an entity is loaded - must either be a loaded proxy or not a proxy
private
isLoaded(object $entity) : bool
Parameters
- $entity : object
Return values
boolmergeEntityStateIntoManagedCopy()
private
mergeEntityStateIntoManagedCopy(object $entity, object $managedCopy) : void
Parameters
- $entity : object
- $managedCopy : object
Tags
newInstance()
private
newInstance(ClassMetadata $class) : object
Parameters
- $class : ClassMetadata
Return values
objectnormalizeIdentifier()
Given a flat identifier, this method will produce another flat identifier, but with all association fields that are mapped as identifiers replaced by entity references, recursively.
private
normalizeIdentifier(ClassMetadata $targetClass, array<string|int, mixed> $flatIdentifier) : array<string, mixed>
Parameters
- $targetClass : ClassMetadata
- $flatIdentifier : array<string|int, mixed>
Return values
array<string, mixed>objToStr()
Helper method to show an object as string.
private
static objToStr(object $obj) : string
Parameters
- $obj : object
Return values
stringperformCallbackOnCachedPersister()
Performs an action after the transaction.
private
performCallbackOnCachedPersister(callable $callback) : void
Parameters
- $callback : callable
persistNew()
private
persistNew(ClassMetadata $class, object $entity) : void
Parameters
- $class : ClassMetadata
- $entity : object
Tags
postCommitCleanup()
private
postCommitCleanup(object|array<string|int, object>|null $entity) : void
Parameters
- $entity : object|array<string|int, object>|null
updateAssociationWithMergedEntity()
Sets/adds associated managed copies into the previous entity's association field
private
updateAssociationWithMergedEntity(object $entity, array<string|int, mixed> $association, mixed $previousManagedCopy, mixed $managedCopy) : void
Parameters
- $entity : object
- $association : array<string|int, mixed>
- $previousManagedCopy : mixed
- $managedCopy : mixed