Symfony: EventDispatcher bug?

Created on 18 Mar 2014  路  3Comments  路  Source: symfony/symfony

Hi, my project is in Symfony 2.4 and I'm listening the security.interactive_login event to perform some operations one user login success and redirect him to a specific page. In my Listener class, I clearly stated the use Symfony\Component\EventDispatcher\EventDispatcher declaration. The event_dispatcher is mentioned in the service's arguments. But no matter how hard I try, it always returns this error message:

Argument 6 passed to AuthenticationListener::__construct() must be an instance of Symfony\Component\EventDispatcher\EventDispatcher, instance of Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher given

Can't figure out where this comes from. I'm afraid it is a Symfony 2.4 bug. Any fix please? Thanks

Most helpful comment

You should typehint for the interface instead of the implementation. TraceableEventDispatcher (an event dispatcher used in debug note to keep track of all events) does not extend the default EventDispatcher. That's why it's failing.

Thus, you should change the typehint to Symfony\Component\EventDispatcher\EventDispatcherInterface.

All 3 comments

You should typehint for the interface instead of the implementation. TraceableEventDispatcher (an event dispatcher used in debug note to keep track of all events) does not extend the default EventDispatcher. That's why it's failing.

Thus, you should change the typehint to Symfony\Component\EventDispatcher\EventDispatcherInterface.

@etoileweb as @WouterJ suggested, your service's constructor should expect an instance of EventDispatcherInterface as opposed to a concrete implementation.

Closing as it's clearly a user error.

Thanks, it worked. But I also forgot a use Symfony\Component\HttpKernel\KernelEvents statement.

Was this page helpful?
0 / 5 - 0 ratings