@@ -124,21 +124,22 @@ a ``postPersist()`` method, which will be called when the event is dispatched::
124
124
// src/AppBundle/EventListener/SearchIndexer.php
125
125
namespace AppBundle\EventListener;
126
126
127
- use Doctrine\ORM\Event\LifecycleEventArgs;
127
+ // for Doctrine < 2.4: use Doctrine\ORM\Event\LifecycleEventArgs;
128
+ use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
128
129
use AppBundle\Entity\Product;
129
130
130
131
class SearchIndexer
131
132
{
132
133
public function postPersist(LifecycleEventArgs $args)
133
134
{
134
- $entity = $args->getEntity ();
135
+ $entity = $args->getObject ();
135
136
136
137
// only act on some "Product" entity
137
138
if (!$entity instanceof Product) {
138
139
return;
139
140
}
140
141
141
- $entityManager = $args->getEntityManager ();
142
+ $entityManager = $args->getObjectManager ();
142
143
// ... do something with the Product
143
144
}
144
145
}
@@ -195,11 +196,11 @@ interface and have an event method for each event it subscribes to::
195
196
196
197
public function index(LifecycleEventArgs $args)
197
198
{
198
- $entity = $args->getEntity ();
199
+ $entity = $args->getObject ();
199
200
200
201
// perhaps you only want to act on some "Product" entity
201
202
if ($entity instanceof Product) {
202
- $entityManager = $args->getEntityManager ();
203
+ $entityManager = $args->getObjectManager ();
203
204
// ... do something with the Product
204
205
}
205
206
}
0 commit comments