Magento:重写事件观察者核心类是否安全?
假设,核心中有一个事件观察者类。我可以覆盖它。但是,安全吗?我的意思是,它会影响观察者类的其他功能吗?
就像,如果核心观察者类中有两个函数,而我只重写了一个函数。那么其他功能是否还能像以前一样安全地工作呢?
我认为它与模型覆盖类似并且应该是安全的。我说得对吗?
编辑:-
例如,
- 核心中有一个类CoreClassA。
- CoreClassA中有一个函数coreFunctionA。
- 在此 coreFunctionA 中调度事件 core_event_a。
- 另一个核心模块CoreModuleB正在使用core_event_a创建事件观察器。
- 因此,每当调度 core_event_a 时,都会调用 CoreModuleB 的事件观察器。
- 假设CoreModuleB的事件观察器包含两个函数。一个用于 core_event_a 调度操作(让我们将其命名为 eventDispatchA),另一个用于其他事件调度操作(例如 eventDispatchX)。
- 在我的自定义模块中,我想覆盖 eventDispatchA。 基本上,我想更改 eventDispatchA 中的一些代码,或者,我可能只想跳过/省略此函数。我可以覆盖它。 但是,如果我这样做,会影响 eventDispatchX 吗?或者,除了重写事件观察者之外,还有其他更好的方法吗?
Suppose, there is an event observer class in core. I can override it. But, is it safe? I mean, does it affect other functions of the observer class?
Like, if there are two functions in core observer class and I did override only one function. Then, will the other function work safely as before.
I think it is similar to model override and should be safe. Am I right?
Edit:-
For example,
- There is a class CoreClassA in core.
- There is a function coreFunctionA in CoreClassA.
- An event core_event_a is dispatched in this coreFunctionA.
- Another core module CoreModuleB is creating event observer with core_event_a.
- So, whenever core_event_a is dispatched, CoreModuleB's event observer is called.
- Suppose, CoreModuleB's event observer contains two functions. One for core_event_a dispatch action (let us name it eventDispatchA) and another for some other event dispatch action (let's say eventDispatchX).
- In my custom module, I want to override eventDispatchA. Basically, I want to change the some code in eventDispatchA or, I may just want to skip/omit this function. I can override it. But, will it affect eventDispatchX if I do so? Or, is there any other better way instead of overriding event observer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最有可能的是,但如果你覆盖其他人可能正在使用的东西,那么总是值得做类似的东西:
正如其他人告诉你的那样:“如果你需要更改/覆盖核心,那么你可能做错了”并且最好以不同的方式提出问题,描述你想做什么以及为什么
Most probably it will but if you override something that others might be using it's always worth to make something similar:
and as others have told you : "if you are in need to change/override the core then you are probably doing it wrong" and it's better to ask in different manner by describing what you want to do and why