3

In Symfony after creating a Doctrine postPersist EventListener, my IDE pointed to the $args->getEntity() line; As being deprecated, I do not know how I can remedy this because it is the same code as in the Symfony docs for version 2.8

Screenshot from IDE PhpStorm: https://image.prntscr.com/image/tT4zAlXkQMOxqvo6TLblUg.png

Code:

public function postPersist(LifecycleEventArgs $args)
{
    $entity = $args->getEntity();

    // ...
}
Jason Roman
  • 8,146
  • 10
  • 35
  • 40
helmis.m
  • 234
  • 1
  • 18

2 Answers2

7

In your eventlistener class in use, i guess you set the bad class.

use Doctrine\Common\Persistence\Event\LifecycleEventArgs; -> the getEntity() method is deprecated.

You should use :

use Doctrine\ORM\Event\LifecycleEventArgs;
Athos
  • 181
  • 6
2

You can use $args->getObject() instead, it returns the same object as getEntity().

More info : http://www.doctrine-project.org/api/common/2.4/source-class-Doctrine.Common.Persistence.Event.LifecycleEventArgs.html#70-78

If you use Doctrine < 2.4, you should use Doctrine\ORM\Event\LifecycleEventArgs

Thlbaut
  • 649
  • 7
  • 25