Skip to content

Instantly share code, notes, and snippets.

@ismail1432
Last active October 31, 2019 22:59
Show Gist options
  • Save ismail1432/facae7e80fc839b1d339c2e38a6e8f75 to your computer and use it in GitHub Desktop.
Save ismail1432/facae7e80fc839b1d339c2e38a6e8f75 to your computer and use it in GitHub Desktop.
<?php
class UserSubscriber
{
public function postPersist(LifecycleEventArgs $args)
{
$entity = $args->getObject();
// if this listener only applies to certain entity types,
// add some code to check the entity type as early as possible
if (!$this->supports($entity)) {
return;
}
$entityManager = $args->getObjectManager();
// ... do something with the User entity
}
public function supports($entity): bool
{
return $entity instanceof User;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment