I have this abstract parent class with some restrictions.
namespace FileBundle\AbstractClass;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use FileBundle\Interfaces\IFileOid;
use FileBundle\Traits\TFileOid;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\MappedSuperclass()
* @ORM\HasLifecycleCallbacks()
*/
abstract class AbstractFileOid implements IFileOid
{
/**
* Set trait
*/
use TFileOid;
/**
* @param UploadedFile|null $fileTemp
*
* @return void
*/
abstract public function init(UploadedFile $fileTemp = null);
// and some next code here
}
As you can see, I use there a trait called "TFileOid" which contains some methods using orm lifecycle events like PostLoad(), PostPersist() etc..
And there is child class (entity) that extends the abstract parent:
namespace FileBundle\Entity;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use FileBundle\AbstractClass\AbstractFileOid;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity()
* @ORM\Table("files")
*/
class MyFile extends AbstractFileOid
{
/**
* @var string
* @ORM\Id
* @ORM\Column(type="string", length=40)
*/
private $hash;
/**
* @ORM\Column(type = "oid", nullable = true)
*/
private $data;
// and some next code
}
My issue is when I use ORM\HasLifecycleCallbacks on the parent abstract class, the event methods in the trait will not be called. When I move the ORM\HasLifecycleCallbacks to the child class, it will work. I tried a solution with "MappedSuperclass" definition on the parent, but without success.
Is there any way to define ORM\HasLifecycleCallbacks on the parent and not on the child class?