Using PHP 8 Attribute for event_class_map like EventSerializer & EventVersion #315
Unanswered
walirazzaq
asked this question in
Ideas
Replies: 1 comment 1 reply
-
Not sure whether we want another way of doing the same. I do like your proposal, but ideally it'd be the only way of managing event names in the future, meaning a new major release. One potential problem is that now you'd need to scan all event classes to build the event map. That shouldn't be an issue if we properly cache the results, but that should be taken into consideration as well. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently the only place to define
event_class_map
is the config. It fine for countable events but as no. of events grows it becomes huge and hard to maintain.I was thinking if
AnEventClass
has the mapped name on itself usingPHP Attribute
just we have it forEventVersion
,EventSerializer
and cache them like EventHandlersThis might scatter the names all over the place and can cause name conflicts for not being able to see in one place, but we can throw an exception when composing the names for duplication.
Using named events rather than FQCNs decouples the stored events from code structure which is quite helpful.
Some helper console commands can be there for developer experience to list mapped names or so
I was thinking to pitch similar idea for
Laravel morphMap
but I thought it's almost same and I should get some expert opinion on that 🤔Beta Was this translation helpful? Give feedback.
All reactions