Last active
February 1, 2019 15:12
-
-
Save johnhout/ff1883a2b2f6707d4379db7ccfc48c34 to your computer and use it in GitHub Desktop.
Symfony type listener
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace YourName\YourBundle\EventListener; | |
use Doctrine\ORM\Event; | |
use Symfony\Component\DependencyInjection\ContainerAware; | |
class EntityListener extends ContainerAware | |
{ | |
/** | |
* Gets all the entities to flush | |
* | |
* @param Event\OnFlushEventArgs $eventArgs Event args | |
*/ | |
public function onFlush(Event\OnFlushEventArgs $eventArgs) | |
{ | |
$em = $eventArgs->getEntityManager(); | |
$uow = $em->getUnitOfWork(); | |
//Insertions | |
foreach ($uow->getScheduledEntityInsertions() as $entity) { | |
# your code here for the inserted entities | |
} | |
//Updates | |
foreach ($uow->getScheduledEntityUpdates() as $entity) { | |
# your code here for the updated entities | |
} | |
//Deletions | |
foreach ($uow->getScheduledEntityDeletions() as $entity) { | |
# your code here for the deleted entities | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment