Automatically flushes entity manager on valid symfony response status code.
Works with symfony event dispatcher
Install bundle by composer
composer require temirkhan/flush-listener
Enable it in your app/AppKernel.php
<?php
#app/AppKernel.php
...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
...,
new Temirkhan\FlushListenerBundle\TemirkhanFlushListenerBundle(),
];
}
...
This is it. Now when symfony finishes handling request and return response entity manager will be flushed based on response status code.
To force flushing event dispatcher shall be used.
$dispatcher->dispatch('transaction.commit');
To prevent flushing
$dispatcher->dispatch('transaction.rollback');
This mechanism best suites postgres.