Skip to content

Commit df449a1

Browse files
committed
minor #10228 Removing calls to deprecated code (aequasi)
This PR was squashed before being merged into the 2.8 branch (closes #10228). Discussion ---------- Removing calls to deprecated code getEntity and getEntityManager are deprecated <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/roadmap for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `master` for features of unreleased versions). --> Commits ------- e6efbf9 Removing calls to deprecated code
2 parents f40f946 + e6efbf9 commit df449a1

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

doctrine/event_listeners_subscribers.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)