Making ZF2 services available within Doctrine entities is not as trivial as with objects that are created via the ZF2 factory methods. The problem is that Doctrine Entities are not generated via regular ZF2 factory methods but by the Doctrine Entity Manager. Nevertheless it’s possible to inject dependencies into Doctrine entities.
Doctrine’s event manager offers a postLoad event which is called after the entity has been loaded. We can add a new listener to this event during our regular bootstrapping process.
Continue reading “Injecting ZF2 Service Manager into Doctrine Entities”