@@ -140,6 +140,11 @@ do so, define a listener for the ``postPersist`` Doctrine event::
140140 }
141141 }
142142
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+
143148Then, add the ``#[AsDoctrineListener] `` attribute to the class to enable it as
144149a Doctrine listener in your application::
145150
@@ -438,27 +443,25 @@ want to log all the database activity. To do so, define a subscriber for the
438443 }
439444
440445 // 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
442447 // to both the entity object of the event and the entity manager itself
443448 public function postPersist(PostPersistEventArgs $args): void
444449 {
445- $this->logActivity('persist', $args);
450+ $this->logActivity('persist', $args->getObject() );
446451 }
447452
448453 public function postRemove(PostRemoveEventArgs $args): void
449454 {
450- $this->logActivity('remove', $args);
455+ $this->logActivity('remove', $args->getObject() );
451456 }
452457
453458 public function postUpdate(PostUpdateEventArgs $args): void
454459 {
455- $this->logActivity('update', $args);
460+ $this->logActivity('update', $args->getObject() );
456461 }
457462
458- private function logActivity(string $action, PostUpdateEventArgs|PostRemoveEventArgs|PostPersistEventArgs $args ): void
463+ private function logActivity(string $action, mixed $entity ): void
459464 {
460- $entity = $args->getObject();
461-
462465 // if this subscriber only applies to certain entity types,
463466 // add some code to check the entity type as early as possible
464467 if (!$entity instanceof Product) {
@@ -469,6 +472,11 @@ want to log all the database activity. To do so, define a subscriber for the
469472 }
470473 }
471474
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+
472480If you're using the :ref: `default services.yaml configuration <service-container-services-load-example >`
473481and DoctrineBundle 2.1 (released May 25, 2020) or newer, this example will already
474482work! Otherwise, :ref: `create a service <service-container-creating-service >` for this
0 commit comments