我有一个这样的教义事件听者:
class myListener
{
public function prePersist(LifecycleEventArgs $args): void
{
$entity = $args->getObject();
if ($entity instanceof Item) {
if ($entity->futureDate) {
$this->doSomethingInTheFuture($entity);
} else {
$this->doSomethingNow($entity)
}
}
if ($entity instanceof ImageOfItem) {
if (/*It is in the future*/) {
$this->doSomethingElseInTheFuture($entity); //This is where I am stucked
} else {
$this->doSomethingElseNow($entity);
}
}
}
}
每个实体都有两个功能,具体取决于将来还是现在。
只有实体Item的字段为“ futureDate”。如果实体Item具有Future Date,则ImageOfItem在调用时也应调用doSomethingElseInTheFuture
函数。它们都在控制器中彼此调用。但是,我找不到在侦听器中彼此通信的方法。
是否有一种方法可以给ImageOfItem一个条件,具体取决于Item在侦听器中是否具有property futureDate的属性,而它们都在同一个Controller中被调用?