@@ -119,13 +119,13 @@ do so, define a listener for the ``postPersist`` Doctrine event::
119
119
namespace App\EventListener;
120
120
121
121
use App\Entity\Product;
122
- use Doctrine\Persistence \Event\LifecycleEventArgs ;
122
+ use Doctrine\ORM \Event\PostPersistEventArgs ;
123
123
124
124
class SearchIndexer
125
125
{
126
126
// the listener methods receive an argument which gives you access to
127
127
// 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
129
129
{
130
130
$entity = $args->getObject();
131
131
@@ -167,12 +167,12 @@ listener in the Symfony application by creating a new service for it and
167
167
namespace App\EventListener;
168
168
169
169
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
170
- use Doctrine\ORM\Event\LifecycleEventArgs ;
170
+ use Doctrine\ORM\Event\PostPersistEventArgs ;
171
171
172
172
#[AsDoctrineListener('postPersist'/*, 500, 'default'*/)]
173
173
class SearchIndexer
174
174
{
175
- public function postPersist(LifecycleEventArgs $event): void
175
+ public function postPersist(PostPersistEventArgs $event): void
176
176
{
177
177
// ...
178
178
}
@@ -277,13 +277,13 @@ First, define a PHP class that handles the ``postUpdate`` Doctrine event::
277
277
namespace App\EventListener;
278
278
279
279
use App\Entity\User;
280
- use Doctrine\Persistence \Event\LifecycleEventArgs ;
280
+ use Doctrine\ORM \Event\PostUpdateEventArgs ;
281
281
282
282
class UserChangedNotifier
283
283
{
284
284
// the entity listener methods receive two arguments:
285
285
// 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
287
287
{
288
288
// ... do something to notify the changes
289
289
}
@@ -420,7 +420,9 @@ want to log all the database activity. To do so, define a subscriber for the
420
420
use App\Entity\Product;
421
421
use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
422
422
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;
424
426
425
427
class DatabaseActivitySubscriber implements EventSubscriberInterface
426
428
{
@@ -436,24 +438,24 @@ want to log all the database activity. To do so, define a subscriber for the
436
438
}
437
439
438
440
// 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
440
442
// 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
442
444
{
443
445
$this->logActivity('persist', $args);
444
446
}
445
447
446
- public function postRemove(LifecycleEventArgs $args): void
448
+ public function postRemove(PostRemoveEventArgs $args): void
447
449
{
448
450
$this->logActivity('remove', $args);
449
451
}
450
452
451
- public function postUpdate(LifecycleEventArgs $args): void
453
+ public function postUpdate(PostUpdateEventArgs $args): void
452
454
{
453
455
$this->logActivity('update', $args);
454
456
}
455
457
456
- private function logActivity(string $action, LifecycleEventArgs $args): void
458
+ private function logActivity(string $action, PostUpdateEventArgs|PostRemoveEventArgs|PostPersistEventArgs $args): void
457
459
{
458
460
$entity = $args->getObject();
459
461
0 commit comments