New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Workflow] Add EventNameTrait to compute event name strings in subscribers #54344
Conversation
62740c8
to
3fb63f1
Compare
Did you see #51210? |
Yes! But as event subscribers allow to register events too, shouldn't we take care of their DX too? Or maybe I could leverage the existing code for this? |
IMHO, event listener are better thank event subscriber now. But I think we can do something for the subscriber too. I'll review it |
No. I'd rather get rid of subscribers, tbh. From my POV, the only reason subscribers still exist, is the amount of busy work we would force upon downstream code if we removed them. Regarding DX improvements, I'd keep our efforts focused on attribute-based listeners. |
@derrabus with SF full stack, it's easy to register listener, but without the framework, it's harder. I think it's still better to merge this PR once ready |
6ef6cb5
to
194a623
Compare
Thanks for your feedback! I addressed your comments :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a note in the CHANGELOG ?
👍🏼
2e4ecd0
to
d231549
Compare
Done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
trait EventNameTrait | ||
{ | ||
/** | ||
* Get event name for workflow and transition. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Get event name for workflow and transition. | |
* Gets the event name for workflow and transition. |
} | ||
|
||
/** | ||
* Get event name for workflow and place. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Get event name for workflow and place. | |
* Gets the event name for workflow and place. |
0aad8af
to
742221f
Compare
Thank you @squrious. |
Hello!
Using the event dispatcher, we usually use event's class name to configure the event to listen to. For workflow, we
still have to use raw strings:
Using class names is more clear about what event we use (easier to know which event to use in the listener). Even if we already have attributes to define event listeners, the event subscriber way could be improved.
Proposal
This PR adds a trait to improve DX when using workflow events in event subscribers.
For a better DX, the
EventNameTrait
provides two methods:getNameForPlace
andgetNameForTransition
, so the secondargument of
::get
and its PHPDoc are consistent with the event type.In event classes, it is used like:
Cheers!