maker-bundle icon indicating copy to clipboard operation
maker-bundle copied to clipboard

[Make:Listener] Improve event name matching

Open maelanleborgne opened this issue 1 year ago • 1 comments

Description

When using a class's FQCN as event name, you have to enter the FQCN in the command to make it work.

If the event name given by the user doesn't match a registered event name nor an FQCN, we could try to 'guess' if the input matches a class short name from the App\\ namespace (we could even sneak some levenshtein in there to catch typos) and ask if the user meant one of the matching results.

Do you think that would be doable without ruining the performance (I imagine that on large projects with a lot of classes that could be a rather heavy process) ?

Example

Choose a class name for your event listener or subscriber (e.g. ExceptionListener or ExceptionSubscriber):
 > CustomEventListener

What event do you want to listen to?:
 > MyCustomEvent

Did you mean ... [MyCustomEvent]
[0] MyCustomEvent
[1] App\Event\MyCustomEvent
 > App\Event\MyCustomEvent  # <- Here we would have auto-completion from the suggestions above

maelanleborgne avatar Dec 15 '23 09:12 maelanleborgne

@weaverryan What do you think of this idea ? I started some work on this feature but to list all events, we need to force the declaration of all the classes that extend the Event base class,. I couldn't find a clean way to achieve this.

Maybe just matching on the built-in events (that we can access from the event registry) would be enough ?

maelanleborgne avatar Feb 19 '24 16:02 maelanleborgne