doctrine/doctrine2 — pull request #1022 by dantleech (2014-04-29 17:46:02+00:00)
Title: [POC] Added EndFlush event

This was mentioned on Twitter, this is just a POC to further the discussion.

I have a problem in the PHPCR-ODM, which would be solved by an `endFlush` event.

* We cannot persist additional documents in `postFlush` because the UOW is still in an "active" state at that stage. (and this operation is explicitly prohibited in the documentation)
* We *can* persist additional documents in the `onFlush` event, but its difficult to do this *reactively*.

*Reactivity*: Often we want to persist new documents depending on which objects will be (or have been) persisted. This is possible with `onFlush` because we can access the UOW. However, it does not scale -- what if we want some listener to create new objects dynamically based on objects created dynamically in another listener? We only flush one time, so other listeners may or may not have access to the documents which have been dynamically scheduled for insertion by another listener, depending on the call order.

If we allow the user to persist extra documents in an `endFlush` event, there is no problem.

In regards to the inifinite recursion problem, we could simply not fire the event when there are no objects scheduled to be inserted/updated/removed.