@@ -119,13 +119,13 @@ do so, define a listener for the ``postPersist`` Doctrine event::
119119 namespace App\EventListener;
120120
121121 use App\Entity\Product;
122- use Doctrine\Persistence \Event\LifecycleEventArgs ;
122+ use Doctrine\ORM \Event\PostPersistEventArgs ;
123123
124124 class SearchIndexer
125125 {
126126 // the listener methods receive an argument which gives you access to
127127 // both the entity object of the event and the entity manager itself
128- public function postPersist(LifecycleEventArgs $args): void
128+ public function postPersist(PostPersistEventArgs $args): void
129129 {
130130 $entity = $args->getObject();
131131
@@ -167,12 +167,12 @@ listener in the Symfony application by creating a new service for it and
167167 namespace App\EventListener;
168168
169169 use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
170- use Doctrine\ORM\Event\LifecycleEventArgs ;
170+ use Doctrine\ORM\Event\PostPersistEventArgs ;
171171
172172 #[AsDoctrineListener('postPersist'/*, 500, 'default'*/)]
173173 class SearchIndexer
174174 {
175- public function postPersist(LifecycleEventArgs $event): void
175+ public function postPersist(PostPersistEventArgs $event): void
176176 {
177177 // ...
178178 }
@@ -277,13 +277,13 @@ First, define a PHP class that handles the ``postUpdate`` Doctrine event::
277277 namespace App\EventListener;
278278
279279 use App\Entity\User;
280- use Doctrine\Persistence \Event\LifecycleEventArgs ;
280+ use Doctrine\ORM \Event\PostUpdateEventArgs ;
281281
282282 class UserChangedNotifier
283283 {
284284 // the entity listener methods receive two arguments:
285285 // the entity instance and the lifecycle event
286- public function postUpdate(User $user, LifecycleEventArgs $event): void
286+ public function postUpdate(User $user, PostUpdateEventArgs $event): void
287287 {
288288 // ... do something to notify the changes
289289 }
@@ -420,7 +420,9 @@ want to log all the database activity. To do so, define a subscriber for the
420420 use App\Entity\Product;
421421 use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
422422 use Doctrine\ORM\Events;
423- use Doctrine\Persistence\Event\LifecycleEventArgs;
423+ use Doctrine\ORM\Event\PostPersistEventArgs;
424+ use Doctrine\ORM\Event\PostRemoveEventArgs;
425+ use Doctrine\ORM\Event\PostUpdateEventArgs;
424426
425427 class DatabaseActivitySubscriber implements EventSubscriberInterface
426428 {
@@ -436,24 +438,24 @@ want to log all the database activity. To do so, define a subscriber for the
436438 }
437439
438440 // callback methods must be called exactly like the events they listen to;
439- // they receive an argument of type LifecycleEventArgs , which gives you access
441+ // they receive an argument of type PostPersistEventArgs , which gives you access
440442 // to both the entity object of the event and the entity manager itself
441- public function postPersist(LifecycleEventArgs $args): void
443+ public function postPersist(PostPersistEventArgs $args): void
442444 {
443445 $this->logActivity('persist', $args);
444446 }
445447
446- public function postRemove(LifecycleEventArgs $args): void
448+ public function postRemove(PostRemoveEventArgs $args): void
447449 {
448450 $this->logActivity('remove', $args);
449451 }
450452
451- public function postUpdate(LifecycleEventArgs $args): void
453+ public function postUpdate(PostUpdateEventArgs $args): void
452454 {
453455 $this->logActivity('update', $args);
454456 }
455457
456- private function logActivity(string $action, LifecycleEventArgs $args): void
458+ private function logActivity(string $action, PostUpdateEventArgs|PostRemoveEventArgs|PostPersistEventArgs $args): void
457459 {
458460 $entity = $args->getObject();
459461
0 commit comments