I'm trying to figure out how to implement a good separation of concerns in a Laravel application. I'm planning to use Repository pattern with concrete repositories implemented using Doctrine2.
Now the question is actually simple. Where should I do a EntityManager::flush()
?
As I read on several articles, I should not put an updateModel
operation to modify my objects since I would end up writing business logic in my repositories.
Now, if I only have operations related to persistence and search (find, all, add, remove) in my repositories, where would I do a flush when modifying a persisted object? If I do it in my service classes or in my controller (wherever I'm consuming a repository from) I will be coupling my business logic to Doctrine and that's what I'm trying to avoid. I thought a good option may be to put it somewhere at the end of the request, but this answer says it's not a good idea.
Any advice?