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

[EventDispatcher] no interface for event #9539

Closed
Miliooo opened this issue Nov 19, 2013 · 3 comments
Closed

[EventDispatcher] no interface for event #9539

Miliooo opened this issue Nov 19, 2013 · 3 comments

Comments

@Miliooo
Copy link
Contributor

Miliooo commented Nov 19, 2013

Is there a reason why there is no interface for the event class?
https://github.com/symfony/symfony/blob/master/src/Symfony/Component/EventDispatcher/Event.php

An example

//our FooEvent class

class FooEvent extends Event implements FooEventInterface 
{  
}

This makes it impossible to do the code below

//our FooEventInterface

interface FooEventInterface extends EventInterface 
{   
}

Since there is no Event Interface the code above is not possible and without it we don't provide the public methods of the event class. Is there a good reason symfony does not provide this interface class? Should we not rely on interfaces when dispatching an event?

@stof
Copy link
Member

stof commented Nov 19, 2013

An event is a value object, this is why Symfony does not define an interface for it

@Miliooo
Copy link
Contributor Author

Miliooo commented Nov 19, 2013

Thanks for the answer. Guess I'll rely on concrete classes when dispatching events. I never saw events as value objects, but it does make sense to threat them that way.

@Miliooo Miliooo closed this as completed Nov 19, 2013
Miliooo added a commit to Miliooo/MilioooMessageBundle that referenced this issue Nov 19, 2013
@stof
Copy link
Member

stof commented Nov 19, 2013

well, the event is a value object passing the data to the listener.

Note that as of Symfony 2.4 (currently master), the event listener will receive 3 arguments: the event object, the event name and the dispatcher. In previous versions, you have to get the event name and the dispatcher from the event object (which is something we want to drop in 3.0, hence the new arguments)

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

2 participants