@@ -124,21 +124,22 @@ a ``postPersist()`` method, which will be called when the event is dispatched::
124124 // src/AppBundle/EventListener/SearchIndexer.php
125125 namespace AppBundle\EventListener;
126126
127- use Doctrine\ORM\Event\LifecycleEventArgs;
127+ // for Doctrine < 2.4: use Doctrine\ORM\Event\LifecycleEventArgs;
128+ use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
128129 use AppBundle\Entity\Product;
129130
130131 class SearchIndexer
131132 {
132133 public function postPersist(LifecycleEventArgs $args)
133134 {
134- $entity = $args->getEntity ();
135+ $entity = $args->getObject ();
135136
136137 // only act on some "Product" entity
137138 if (!$entity instanceof Product) {
138139 return;
139140 }
140141
141- $entityManager = $args->getEntityManager ();
142+ $entityManager = $args->getObjectManager ();
142143 // ... do something with the Product
143144 }
144145 }
@@ -195,11 +196,11 @@ interface and have an event method for each event it subscribes to::
195196
196197 public function index(LifecycleEventArgs $args)
197198 {
198- $entity = $args->getEntity ();
199+ $entity = $args->getObject ();
199200
200201 // perhaps you only want to act on some "Product" entity
201202 if ($entity instanceof Product) {
202- $entityManager = $args->getEntityManager ();
203+ $entityManager = $args->getObjectManager ();
203204 // ... do something with the Product
204205 }
205206 }
0 commit comments