@ takehin: Спасибо, что поделились своим плагином, это здорово!И именно то, что я искал на машине Google.
Я внес некоторые изменения, с уважением, в логику, которая определяет запрос как «запрос об ошибке», так как я обнаружил, что полный обратный вызов плагина выполнялся при каждом запросе, независимо от того, была ли ошибкаПроизошло.
Я просто изменил хук плагина на «postDispatch» и проверил, что во время отправки действительно произошло исключение.Остальная часть кода работает точно так же, как ваша.
Теперь вы можете поместить оператор die в середину плагина, и вы увидите его только после того, как во время запроса возникнет исключение.
<?php
class Rm_Controller_Plugin_Modular_ErrorController
extends Zend_Controller_Plugin_Abstract
{
public function postDispatch(Zend_Controller_Request_Abstract $request)
{
$front = Zend_Controller_Front::getInstance();
// true if response has any exception
$isError = $front->getResponse()->hasExceptionOfType('Exception');
// if there was no error during dispatch
if (!$isError) {
return false;
}
// standard error handler plugin class name
$errorHandlerClass = 'Zend_Controller_Plugin_ErrorHandler';
// if the error handler plugin is not registered, do not continue.
if (!$front->hasPlugin($errorHandlerClass)) {
return false;
}
$plugin = $front->getPlugin($errorHandlerClass);
// the module that was requested and threw error
$module = $request->getModuleName();
// the controller & action name that error handler will dispatch
$errorController = $plugin->getErrorHandlerController();
$errorAction = $plugin->getErrorHandlerAction();
// create a dummy request to test for dispatchablility
$testRequest = new Zend_Controller_Request_Http();
$testRequest->setModuleName($module)
->setControllerName($errorController)
->setActionName($errorAction);
// verify that the current module has defined an ErrorController::errorAction
if ($front->getDispatcher()->isDispatchable($testRequest)) {
// tell error controller plugin to use the module's error controller
$plugin->setErrorHandlerModule($module);
} else {
return false;
}
return true;
}
}