8000 minor #5828 move the getEntityManager, only get it if needed (OskarSt… · symfony/symfony-docs@a392041 · GitHub
[go: up one dir, main page]

Skip to content

Commit a392041

Browse files
committed
minor #5828 move the getEntityManager, only get it if needed (OskarStark)
This PR was submitted for the 2.7 branch but it was merged into the 2.3 branch instead (closes #5828). Discussion ---------- move the getEntityManager, only get it if needed if this will be merged, please be sure, that this is the correct branch! Thank you Commits ------- 1498140 move the getEntityManager, only get it if needed
2 parents 10d2158 + 1498140 commit a392041

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)
0