获取当前调度的事件列表

发布于 2024-10-29 19:41:35 字数 387 浏览 1 评论 0原文

我知道这个问题可能看起来很奇怪,但我想获取当前已调度事件的列表。 问题是我是一个懒惰的人,我想检查“checkout_cart_add_product_complete”是否已被解雇而不为其创建观察者。

所以我们的想法是获取所有已调度事件的数组并对其执行 in_array :)

我认为 Mage::getEvents()->getAllEvents() 会抛出一些信息,但它只返回一个空数组。

我还深入研究了 lib/Varien/Event 文件和文件夹,但未能成功以编程方式创建观察者。是的,我知道,为什么要简单而复杂呢? :)

所以这个主要问题(获取已调度事件的列表)隐藏了另一个(纯粹的知识),即“如何以编程方式创建观察者”。

你怎么认为?

多谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

抚笙 2024-11-05 19:41:35

看一下 dispatchEvent,您会发现事件仅通过 SimpleXML 从分类的 config.xml 文件中加载。除了覆盖 Mage_Core_Model_App 之外,我看不到任何方法来拦截此行为。

当然,不可能存在事件调度事件,这会创建无限循环,因此无法观察所有事件。

如果您需要查看开发事件,我的建议是使用调试器在 dispatchEvent 中设置断点,这样您不仅可以看到事件名称,还可以看到作为参数传递的对象。我之前尝试过其他方法,但这对我来说最方便。

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.

季末如歌 2024-11-05 19:41:35

我需要做同样的事情,我认为可以通过 Mage_Core_Model_Config 中的函数 getEventConfig 来欺骗 magento。您可以强制他自动添加默认观察者。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文