Get list of currently dispatched events

I know this question may seem weird but I’d like to get a list of currently dispatched events.
The thing is that I am a lazy man and I would like to check if the ‘checkout_cart_add_product_complete’ has been fired without creating an observer for it.

So the idea is to get an array of all dispatched events and do an in_array on it 🙂

I thought that Mage::getEvents()->getAllEvents() would throw some info but it just returns an empty array.

I also digged a bit in lib/Varien/Event files and folders but didn’t manage to be successful at creating an observer programmatically. Yep, I know, why being simple while one can be complicated ? 🙂

So this main question (getting a list of dispatched events) hides another (for the pure knowledge) wich would be “how to create an observer programmatically”.

What do you think?

Thanks a lot!

2 thoughts on “Get list of currently dispatched events”

  1. Take a look at dispatchEvent and you’ll see that events are only loaded from the assorted config.xml files, via SimpleXML. I cannot see any way to intercept this except to override Mage_Core_Model_App.

    Of course there cannot be an event-dispatched-event, that would create an infinite loop, so there is no way to observe all events.

    If you need to see events for development my advice would be to set a breakpoint in dispatchEvent with your debugger, that way you get to see not only the event names but also the objects passed as parameters too. I’ve tried other ways before but this was most convenient for me.

  2. I need to do the same and I think it’s possible to trick magento by the function getEventConfig in Mage_Core_Model_Config. You could force him to add automatically a default observer.

Leave a Reply

Your email address will not be published. Required fields are marked *