pzaj
pzaj

Reputation: 1092

Symfony2 dispatch new event from event subscriber

I just started Symfony2 web app project and I'm stuck at a particular problem:

I have users and I have one subscriber to doctrine events (postUpdate and postPersist) to dispatch custom events, so:

  1. User is updated
  2. Doctrine flushes User
  3. Doctrine subscriber act on postUpdate dispatching 'user.updated' event
  4. Custom event subscriber act on 'user.updated'

Everything goes fine up to that point. What I need to do now is... I need to dispatch 'user.updated_current' if the user modified is current user from within that custom event subscriber (which also subscribes to 'user.updated_current').

Unfortunately 'user.updated_current' event, despite being dispatched, is not handled by my custom event subscriber.

I'm wondering if I actually can dispatch events from within Symfony's event subscriber?

Upvotes: 1

Views: 554

Answers (1)

Massimiliano Arione
Massimiliano Arione

Reputation: 2466

Just inject event_dispatcher in your subscriber and dispatch your event

Upvotes: 2

Related Questions