Documentation

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
psalm-import-type

AssociationMapping from ClassMetadata

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

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

$collectionDeletions

All pending collection deletions.

private mixed $collectionDeletions = []
Tags
psalm-var

array<int, PersistentCollection<array-key, object>>

$collectionPersisters

The collection persister instances used to persist collections.

private mixed $collectionPersisters = []
Tags
psalm-var

array<array-key, CollectionPersister>

$collectionUpdates

All pending collection updates.

private mixed $collectionUpdates = []
Tags
psalm-var

array<int, PersistentCollection<array-key, object>>

$eagerLoadingEntities

Map of Entity Class-Names and corresponding IDs that should eager loaded when requested.

private mixed $eagerLoadingEntities = []
Tags
psalm-var

array<class-string, array<string, mixed>>

$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
psalm-var

array<int, array<string, array{mixed, mixed}>>

$entityDeletions

A list of all pending entity deletions.

private mixed $entityDeletions = []
Tags
psalm-var

array<int, object>

$entityIdentifiers

Map of all identifiers of managed entities.

private array<string|int, mixed> $entityIdentifiers = []

Keys are object ids (spl_object_id).

Tags
psalm-var

array<int, array<string, mixed>>

$entityInsertions

A list of all pending entity insertions.

private mixed $entityInsertions = []
Tags
psalm-var

array<int, object>

$entityStates

The (cached) states of any known entities.

private mixed $entityStates = []

Keys are object ids (spl_object_id).

Tags
psalm-var

array<int, self::STATE_*>

$entityUpdates

A list of all pending entity updates.

private mixed $entityUpdates = []
Tags
psalm-var

array<int, object>

$extraUpdates

Any pending extra updates that have been scheduled by persisters.

private mixed $extraUpdates = []
Tags
psalm-var

array<int, array{object, array<string, array{mixed, mixed}>}>

$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
psalm-var

array<class-string, array<string, object>>

$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
psalm-var

array<int, array<string, mixed>>

$orphanRemovals

Orphaned entities that are scheduled for removal.

private mixed $orphanRemovals = []
Tags
psalm-var

array<int, object>

$persisters

The entity persister instances used to persist entity instances.

private mixed $persisters = []
Tags
psalm-var

array<string, EntityPersister>

$readOnlyObjects

Read-Only objects are never evaluated

private array<int, true> $readOnlyObjects = []

$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
psalm-var

array<class-string, array<int, mixed>>

$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
psalm-var

array<int, PersistentCollection<array-key, object>>

Methods

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
throws
ORMInvalidArgumentException

if an invalid entity name is given.

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:

  1. All entity insertions
  2. All entity updates
  3. All collection deletions
  4. All collection updates
  5. All entity deletions
Parameters
$entity : object|array<string|int, mixed>|null = null
Tags
throws
Exception

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
psalm-param

AssociationMapping $association

Return values
CollectionPersister

getEntityChangeSet()

Gets the changeset for an entity.

public & getEntityChangeSet(object $entity) : array<string|int, array<string|int, mixed>>
Parameters
$entity : object
Tags
psalm-return

array<string, array{mixed, mixed}|PersistentCollection>

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
psalm-param

class-string $entityName

Return values
EntityPersister

getEntityState()

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
psalm-param

self::STATE_*|null $assume

psalm-return

self::STATE_*

Return values
int

The entity state.

getIdentityMap()

Gets the identity map of the UnitOfWork.

public getIdentityMap() : mixed
Tags
psalm-return

array<class-string, array<string, object>>

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
psalm-return

array<string, mixed>

Return values
array<string|int, mixed>

getScheduledCollectionDeletions()

Gets the currently scheduled complete collection deletions

public getScheduledCollectionDeletions() : mixed
Tags
psalm-return

array<int, PersistentCollection<array-key, object>>

getScheduledCollectionUpdates()

Gets the currently scheduled collection inserts, updates and deletes.

public getScheduledCollectionUpdates() : mixed
Tags
psalm-return

array<int, PersistentCollection<array-key, object>>

getScheduledEntityDeletions()

Gets the currently scheduled entity deletions in this UnitOfWork.

public getScheduledEntityDeletions() : mixed
Tags
psalm-return

array<int, object>

getScheduledEntityInsertions()

Gets the currently scheduled entity insertions in this UnitOfWork.

public getScheduledEntityInsertions() : mixed
Tags
psalm-return

array<int, object>

getScheduledEntityUpdates()

Gets the currently scheduled entity updates in this UnitOfWork.

public getScheduledEntityUpdates() : mixed
Tags
psalm-return

array<int, object>

getSingleIdentifierValue()

Processes an entity instance to extract their identifier values.

public getSingleIdentifierValue(object $entity) : mixed
Parameters
$entity : object

The entity instance.

Tags
throws
ORMInvalidArgumentException
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

isEntityScheduled()

Checks whether an entity is scheduled for insertion, update or deletion.

public isEntityScheduled(object $entity) : bool
Parameters
$entity : object
Return values
bool

isInIdentityMap()

Checks whether an entity is registered in the identity map of this UnitOfWork.

public isInIdentityMap(object $entity) : bool
Parameters
$entity : object
Return values
bool

isScheduledForDelete()

Checks whether an entity is registered as removed/deleted with the unit of work.

public isScheduledForDelete(object $entity) : bool
Parameters
$entity : object
Return values
bool

isScheduledForDirtyCheck()

Checks whether an entity is registered to be checked in the unit of work.

public isScheduledForDirtyCheck(object $entity) : bool
Parameters
$entity : object
Return values
bool

isScheduledForInsert()

Checks whether an entity is scheduled for insertion.

public isScheduledForInsert(object $entity) : bool
Parameters
$entity : object
Return values
bool

isScheduledForUpdate()

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
bool

loadCollection()

Initializes (loads) an uninitialized persistent collection of an entity.

public loadCollection(PersistentCollection $collection) : void
Parameters
$collection : PersistentCollection

The collection to initialize.

Tags
todo

Maybe later move to EntityManager#initialize($proxyOrCollection). See DDC-733.

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
throws
ORMInvalidArgumentException

merge()

Merges the state of the given detached entity into this UnitOfWork.

public merge(object $entity) : object
Parameters
$entity : object
Tags
deprecated
2.7

This method is being removed from the ORM and won't have any replacement

throws
OptimisticLockException

If the entity uses optimistic locking through a version attribute and the version check against the managed copy fails.

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
throws
InvalidArgumentException

If the entity is not MANAGED.

throws
TransactionRequiredException

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.

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
todo

Rename: scheduleForSynchronization

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
throws
ORMInvalidArgumentException
throws
InvalidArgumentException

scheduleForUpdate()

Schedules an entity for being updated.

public scheduleForUpdate(object $entity) : void
Parameters
$entity : object

The entity to schedule for being updated.

Tags
throws
ORMInvalidArgumentException

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
int

triggerEagerLoads()

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
psalm-param

class-string $rootClassName

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
psalm-param

ClassMetadata<T> $class

psalm-param

T $entity

template

T of object

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

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
psalm-param

array<int, object> $visited

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
psalm-param

array<int, object> $visited

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
psalm-param

array<int, object> $visited

psalm-param

LockMode::*|null $lockMode

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
psalm-param

array<int, object> $visited

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
psalm-param

AssociationMapping $assoc The association mapping.

throws
ORMInvalidArgumentException
throws
ORMException

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
  1. All entities scheduled for insertion, (orphan) removals and changes in collections are processed as well!
  2. Read Only entities are skipped.
  3. Proxies are skipped.
  4. Only if entity is properly managed.
Parameters
$entity : object
Tags
throws
InvalidArgumentException

convertSingleFieldIdentifierToPHPValue()

private convertSingleFieldIdentifierToPHPValue(ClassMetadata $class, mixed $identifierValue) : mixed
Parameters
$class : ClassMetadata
$identifierValue : mixed
Tags
throws
MappingException

if the entity has more than a single identifier.

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
psalm-param

AssociationMapping|null $assoc

psalm-param

array<int, object> $visited

throws
OptimisticLockException

If the entity uses optimistic locking through a version attribute and the version check against the managed copy fails.

throws
ORMInvalidArgumentException

If the entity instance is NEW.

throws
EntityNotFoundException

if an assigned identifier is used in the entity, but none is provided.

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
psalm-param

array<int, object> $visited The already visited entities.

throws
ORMInvalidArgumentException
throws
UnexpectedValueException

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
psalm-param

array<int, object> $visited The already visited entities during cascades.

psalm-param

LockMode::*|null $lockMode

throws
ORMInvalidArgumentException

If the entity is not MANAGED.

throws
TransactionRequiredException

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
psalm-param

array<int, object> $visited The map of the already visited entities.

throws
ORMInvalidArgumentException

If the instance is a detached entity.

throws
UnexpectedValueException

ensureVersionMatch()

private ensureVersionMatch(ClassMetadata $class, object $entity, object $managedCopy) : void
Parameters
$class : ClassMetadata
$entity : object
$managedCopy : object
Tags
psalm-param

ClassMetadata<T> $class

psalm-param

T $entity

psalm-param

T $managedCopy

throws
OptimisticLockException
template

T of object

executeExtraUpdates()

Executes any extra updates that have been scheduled.

private executeExtraUpdates() : void

hasMissingIdsWhichAreForeignKeys()

private hasMissingIdsWhichAreForeignKeys(ClassMetadata $class, array<string|int, mixed> $idValue) : bool
Parameters
$class : ClassMetadata
$idValue : array<string|int, mixed>
Return values
bool

isIdentifierEquals()

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
bool

isLoaded()

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
bool

normalizeIdentifier()

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
string

performCallbackOnCachedPersister()

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
psalm-param

ClassMetadata<T> $class

psalm-param

T $entity

template

T of object

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
Tags
psalm-param

AssociationMapping $association


        
On this page

Search results