ZF2 - Error Handling for a Specific Module Only

回眸只為那壹抹淺笑 提交于 2019-12-11 18:17:25

问题


I have a multi-modular app.

And one of its modules listens to "dispatch.error" with 999 priority. And it appears to catch errors from all other modules.

What I need is to catch error in my specific module only and behave appropriately. It will work if I for example will listen to "dispatch.error" with 1000 priority and filter out errors specific to my module (by exception names or using route filtering), but there's no guarantee that some other module won't come with 10000 priority for the same event.

I'm pretty new to ZF2 and don't know if there's a proper way to solve this.

It looks like this question about the same: ZF2: How to attach module specific listener for dispatch.error, but the response does not help at all though it is accepted.

Update: I found out, that it could be fixed by changing DispatchListener.php (when using custom ID within SharedEventManager).

DispatchListener gets EventManager like this:

$events  = $application->getEventManager();

But if controller exists this could be overridden with:

$events = $controller->getEventManager();

And then the issue with module-specific error handlers would be solved.

Does anyone know solutions without fixing of core files? And is it actually a bug (that custom module can listen to "dispatch" for example, but cannot listen to "dispatch.error")

来源:https://stackoverflow.com/questions/49572417/zf2-error-handling-for-a-specific-module-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!