Skip to content
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

Allow for listening for parent classes or interfaces #196

Merged
merged 3 commits into from
Jan 6, 2025

Conversation

inxilpro
Copy link
Contributor

Right now, Verbs looks up hooks specifically by the class name. So if you have a listener that listens for the root Event class, or an interface that your events implement, Verbs will not know to trigger it. This PR adds support for any of those scenarios:

interface IsSpecialEvent {}

class NormalEvent extends Event {}

class SpecialEvent extends Event implements IsSpecialEvent {}

class MyListener
{
    public function listenForJustNormalEvent(NormalEvent $event)
    {
        // Only gets triggered when the `NormalEvent` class is fired
    }

    public function listenForAnySpecialEvent(IsSpecialEvent $event)
    {
        // Gets triggered when any event that implements `IsSpecialEvent`
    }

    public function listenForAllEvents(Event $event)
    {
        // Gets triggered when on all events
    }
}

@inxilpro inxilpro merged commit 28c9bc1 into main Jan 6, 2025
@inxilpro inxilpro deleted the hook-class-hierarchy branch January 6, 2025 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant