preFlush: PreFlushEventArgs should contain the entity being flushed #5267

Closed
opened 2026-01-22 15:03:01 +01:00 by admin · 4 comments
Owner

Originally created by @andreas-glaser on GitHub (Sep 21, 2016).

Originally assigned to: @Ocramius on GitHub.

I'm working on a small library and found myself in need of the entity that is being flushed within the preFlush event. This should be part of the PreFlushEventArgs object in my opinion.

<?php
// UnitOfWork.php 
// ...
public function commit($entity = null)
    {
        // Raise preFlush
        if ($this->evm->hasListeners(Events::preFlush)) {
            $this->evm->dispatchEvent(Events::preFlush, new PreFlushEventArgs($this->em, $entity));
        }
// ...

Any thoughts on this?

Originally created by @andreas-glaser on GitHub (Sep 21, 2016). Originally assigned to: @Ocramius on GitHub. I'm working on a small library and found myself in need of the entity that is being flushed within the `preFlush` event. This should be part of the `PreFlushEventArgs` object in my opinion. ``` <?php // UnitOfWork.php // ... public function commit($entity = null) { // Raise preFlush if ($this->evm->hasListeners(Events::preFlush)) { $this->evm->dispatchEvent(Events::preFlush, new PreFlushEventArgs($this->em, $entity)); } // ... ``` Any thoughts on this?
admin added the Duplicate label 2026-01-22 15:03:01 +01:00
admin closed this issue 2026-01-22 15:03:01 +01:00
Author
Owner

@coudenysj commented on GitHub (Sep 27, 2016):

The preFlush event occurs before the changes are computed in the UnitOfWork. At this point, the UnitOfWork is not aware which entities should be flushed (the $entity parameter is optional).

Cant you use the onFlush event?

@coudenysj commented on GitHub (Sep 27, 2016): The preFlush event occurs before the changes are computed in the UnitOfWork. At this point, the UnitOfWork is not aware which entities should be flushed (the $entity parameter is optional). Cant you use the onFlush event?
Author
Owner

@andreas-glaser commented on GitHub (Sep 27, 2016):

Yes it does occur before but the commit function "knows" whether a specific or any altered entity should be updated. Unfortunately i cannot use the onFlush event as my library does some preprocessing before any change-sets are calculated.

It just seems that the preFlush event should be aware of the $entity argument being passed into the method. I mean without it there is very little use for the event... or at least I cannot think of any uses.

https://github.com/andreas-glaser/dc-event-bundle/tree/1.1

@andreas-glaser commented on GitHub (Sep 27, 2016): Yes it does occur before but the `commit` function "knows" whether a specific or any altered entity should be updated. Unfortunately i cannot use the `onFlush` event as my library does some preprocessing before any change-sets are calculated. It just seems that the `preFlush` event should be aware of the `$entity` argument being passed into the method. I mean without it there is very little use for the event... or at least I cannot think of any uses. https://github.com/andreas-glaser/dc-event-bundle/tree/1.1
Author
Owner

@linaori commented on GitHub (Oct 2, 2016):

see #5848

@linaori commented on GitHub (Oct 2, 2016): see #5848
Author
Owner

@Ocramius commented on GitHub (Oct 2, 2016):

Closing as duplicate.

@Ocramius commented on GitHub (Oct 2, 2016): Closing as duplicate.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5267