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

Add support for something like EventObject in dispatchEvent method #76

Closed
icaine opened this issue Jun 1, 2015 · 10 comments
Closed

Add support for something like EventObject in dispatchEvent method #76

icaine opened this issue Jun 1, 2015 · 10 comments

Comments

@icaine
Copy link

icaine commented Jun 1, 2015

I would like to use something similar to $em->dispatchEvent(new App\Events\StartupEvent(...)) instead of $em->dispatchEvent('app.startup', ...) . Because this way i dont have to remeber exact "string" name of the event and what parameters/arguments i need.

It also may be easily implemented to dispatchEvent method:

if ($eventName instanceof Kdyby\Events\EventObject) {
    $eventArgs = new EventArgsList(array($eventName));
    $eventName = get_class($eventName);
}

What do you think about it?

@fprochazka
Copy link
Member

On the first look, I really like the idea, but I'm not sure if there aren't any non-obviouse design issues with it (with usage of the pattern).

@newPOPE
Copy link

newPOPE commented Jun 2, 2015

+1

Maybe new App\Events\StartupEvent(...) is not good example, I like something like new App\Events\AppStartupEvent(...) or new PostCommentedEvent(...)...

@enumag
Copy link
Member

enumag commented Jun 2, 2015

I can see one problem. The EVM would hold a map like [ classname => array_of_listeners ]. Imagine you would want to add some parameters to a existing event - you would extend the event class and add some properties and methods to it. But the extended class would not work because its class name won't be in the map.

(edit) Solution: EventObjectInterface::getEventName().

@klimesf
Copy link
Contributor

klimesf commented Jun 2, 2015

+1 for the idea, events can be more than just data. Great move towards OOP.
+1 for EventObjectInterface::getEventName().

@icaine
Copy link
Author

icaine commented Jun 2, 2015

It is on the programmer to decide whether to use objects or simple arrays. Otherwise we would still use the fastest plain PHP.. :)

@solcik
Copy link

solcik commented Jun 2, 2015

+1

@fprochazka
Copy link
Member

@enumag actually, EVM already considers inheritance.

@enumag
Copy link
Member

enumag commented Jun 2, 2015

@fprochazka I know but that's for listeners, this is different.

@foxycode
Copy link

foxycode commented Jun 4, 2015

+1

@fprochazka
Copy link
Member

I would love to implement this, but it would be out-of-scope. #97 (comment)

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

No branches or pull requests

7 participants