@@ -140,6 +140,11 @@ do so, define a listener for the ``postPersist`` Doctrine event::
140
140
}
141
141
}
142
142
143
+ .. note ::
144
+
145
+ In previous Doctrine versions, instead of ``PostPersistEventArgs ``, you had
146
+ to use ``LifecycleEventArgs ``, which was deprecated in Doctrine ORM 2.14.
147
+
143
148
Then, add the ``#[AsDoctrineListener] `` attribute to the class to enable it as
144
149
a Doctrine listener in your application::
145
150
@@ -438,27 +443,25 @@ want to log all the database activity. To do so, define a subscriber for the
438
443
}
439
444
440
445
// callback methods must be called exactly like the events they listen to;
441
- // they receive an argument of type PostPersistEventArgs , which gives you access
446
+ // they receive an argument of type Post*EventArgs , which gives you access
442
447
// to both the entity object of the event and the entity manager itself
443
448
public function postPersist(PostPersistEventArgs $args): void
444
449
{
445
- $this->logActivity('persist', $args);
450
+ $this->logActivity('persist', $args->getObject() );
446
451
}
447
452
448
453
public function postRemove(PostRemoveEventArgs $args): void
449
454
{
450
- $this->logActivity('remove', $args);
455
+ $this->logActivity('remove', $args->getObject() );
451
456
}
452
457
453
458
public function postUpdate(PostUpdateEventArgs $args): void
454
459
{
455
- $this->logActivity('update', $args);
460
+ $this->logActivity('update', $args->getObject() );
456
461
}
457
462
458
- private function logActivity(string $action, PostUpdateEventArgs|PostRemoveEventArgs|PostPersistEventArgs $args ): void
463
+ private function logActivity(string $action, mixed $entity ): void
459
464
{
460
- $entity = $args->getObject();
461
-
462
465
// if this subscriber only applies to certain entity types,
463
466
// add some code to check the entity type as early as possible
464
467
if (!$entity instanceof Product) {
@@ -469,6 +472,11 @@ want to log all the database activity. To do so, define a subscriber for the
469
472
}
470
473
}
471
474
475
+ .. note ::
476
+
477
+ In previous Doctrine versions, instead of ``Post*EventArgs `` classes, you had
478
+ to use ``LifecycleEventArgs ``, which was deprecated in Doctrine ORM 2.14.
479
+
472
480
If you're using the :ref: `default services.yaml configuration <service-container-services-load-example >`
473
481
and DoctrineBundle 2.1 (released May 25, 2020) or newer, this example will already
474
482
work! Otherwise, :ref: `create a service <service-container-creating-service >` for this
0 commit comments