Details
Description
Support for @EntityListeners
Now subscribers are called for ALL entities, to increase the performance we should allow the configuration listeners for entities that need them.
The @EntityListeners annotation specifies the callback listener classes to be used for an entity or mapped superclass. The @EntityListeners annotation may be applied to an entity class or mapped superclass.
The listenner callbacks methods are annotated by the current callback annotations (@PreUpdate, @PrePersist, etc...)
Example :
/**
* @EntityListeners({"ContractSubscriber"})
*/
class CompanyContract
{
}
class ContractSubscriber
{
/**
* @PrePersist
*/
public function prePersistHandler(CompanyContract $contract)
{
// do something
}
/**
* @PostPersist
* Most of cases just the entity is needed.
* as a second parameter LifecycleEventArgs allow access to the entity manager.
*/
public function postPersistHandler(CompanyContract $contract, LifecycleEventArgs $args)
{
// do something
}
}
$contract = new CompanyFlexContract();
// do something
$em->persist($contract);
I don't see how this could improve performances much: there is only one event manager, so all listeners would be registered in the same. This means that the event manager would then need to contain some checks to know whether the listener should be called for this entity. This means that it will add overhead for all listeners instead of only in listeners needing to check the entity.