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);
fixed : https://github.com/doctrine/doctrine2/commit/71a68a5c6fcd49538c3ef2f86d64bcde1958251c