title: Which event to use to get notified if entity is written to DB (postFlush)?
body: <p>I have an (Doctrine) entity in a Symfony4 project. What I'm looking for is something like a <code>postFlush</code> event (eg <em>after</em> it has been written to the DB).</p>
  <p>I want to notify other systems that if a Customer is updated, I can dispatch a <code>CustomerUpdated($customer-&gt;id)</code> message unto my queues. I'm having difficulty finding the proper listener/eventhandler for this. The current problem is that the event is dispatched BEFORE the DB has written, so the consuming service asks info for an entry that doesn't exist yet (for like 2 seconds) or fetches old data as the DB isn't updated yet.</p>
  <p><strong>What I've tried:</strong></p>
  <ul>
  <li>
  <pre class="lang-php prettyprint-override"><code>class CustomerListener implements EntityListener {
     public function getSubscribedEvents(): array {
        return [ Events::postFlush ];
     }
     public function postFlush(){ die('looking for me?'); }
  }
  </code></pre>
  This does absolutly nothing and fails silently</li>
  <li>I also use the <code>Events::postUpdate</code> event, which doesn't work for new entries (the data isn't flushed to the DB yet, resulting in old data).</li>
  <li>I also use the <code>Events::postPersist</code> event for new items, which doesnt work because the data doesnt exists in the DB yet! (This is my current challenge).</li>
  <li><a href="https://www.doctrine-project.org/projects/doctrine-orm/en/2.11/reference/events.html#reference-events-post-flush" rel="nofollow noreferrer">The Doctrine docs</a> aren't telling me anything useful either (or im not seeing it).</li>
  <li>Off course I've tried researching this, but I cant seem to find anything.</li>
  </ul>
  <p><strong>What I'm looking for:</strong></p>
  <ol>
  <li>Entity gets created OR entity gets updated</li>
  <li>Entity gets written to database</li>
  <li><em>NOW</em> DO SOMETHING HERE. I dont want to alter the entity anymore, just notify other systems AFTER save.</li>
  </ol>
  <p>Both the postPersist and PostUpdate are between point 1&amp;2, and not suitable. I am aware that flush isn't entity specific, but I need <em>something</em>.<br />
  It could be I'm using a listener/eventSubscriber incorrect, at this point i;m seeing the forest for the trees.</p>