Skip to content

Commit 1498140

Browse files
OskarStarkwouterj
authored andcommitted
move the getEntityManager, only get it if needed
1 parent 10d2158 commit 1498140

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

cookbook/doctrine/event_listeners_subscribers.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ a ``postPersist`` method, which will be called when the event is dispatched::
135135
public function postPersist(LifecycleEventArgs $args)
136136
{
137137
$entity = $args->getEntity();
138-
$entityManager = $args->getEntityManager();
139138

140139
// perhaps you only want to act on some "Product" entity
141140
if ($entity instanceof Product) {
141+
$entityManager = $args->getEntityManager();
142142
// ... do something with the Product
143143
}
144144
}
@@ -191,10 +191,10 @@ interface and have an event method for each event it subscribes to::
191191
public function index(LifecycleEventArgs $args)
192192
{
193193
$entity = $args->getEntity();
194-
$entityManager = $args->getEntityManager();
195194

196195
// perhaps you only want to act on some "Product" entity
197196
if ($entity instanceof Product) {
197+
$entityManager = $args->getEntityManager();
198198
// ... do something with the Product
199199
}
200200
}

0 commit comments

Comments
 (0)