问题
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