mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
[question] order of listener method #5391
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @johndodev on GitHub (Jan 20, 2017).
Originally assigned to: @lcobucci on GitHub.
Hello,
I didn't found the answer on the doc so there is the question.
If I have a listener which use annotation, I can have for example multiple "prepersist method" :
The question is, is the order of calls of theses methods "known" and always the same ? I always assumed reflection is used and the order is the order in the file, but is this true ?
(and subquestion, is it a bad practice to do like this ?)
@Ocramius commented on GitHub (Jan 20, 2017):
@johndodev the order is not guaranteed, as we have no regression testing nor specification around it.
@lcobucci commented on GitHub (Jan 20, 2017):
@johndodev it uses reflection indeed but there's no way to guarantee the order.
If you want to create some sort of dependency I'd suggest you to just have one listener that triggers multiple private methods in the right order.
What exactly are you doing (or thinking to do)?
@johndodev commented on GitHub (Jan 20, 2017):
Okay, I guess I have the answer.
@lcobucci I just have some listeners which calculate some fields value of business logic entities, for example for a ticket (like a message to a support team), I may automatically assign a team member for this one, but to do that I may need another calculated field like the role of the author, calculated in another method.
I think I will change some habit, thanks.
Maybe a note here http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#entity-listeners-class would'nt be a bad idea.
@lcobucci commented on GitHub (Jan 20, 2017):
@johndodev I'd suggest you to keep your business logic very far from the ORM event system and use an explicit event dispatcher to handle things.
Could send us a PR with suggestions?