Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Core_controller_Plugin_ErrorHandler extends Zend_Controller_Plugin_ErrorHandler
- {
- const EXCEPTION_ACL = 'EXCEPTION_ACL';
- protected function _handleError(Zend_Controller_Request_Abstract $request)
- {
- $frontController = Zend_Controller_Front::getInstance();
- if ($frontController->getParam('noErrorHandler')) {
- return;
- }
- $response = $this->getResponse();
- if ($this->_isInsideErrorHandlerLoop) {
- $exceptions = $response->getException();
- if (count($exceptions) > $this->_exceptionCountAtFirstEncounter) {
- // Exception thrown by error handler; tell the front controller to throw it
- $frontController->throwExceptions(true);
- throw array_pop($exceptions);
- }
- }
- // check for an exception AND allow the error handler controller the option to forward
- if (($response->isException()) && (!$this->_isInsideErrorHandlerLoop)) {
- $this->_isInsideErrorHandlerLoop = true;
- // Get exception information
- $error = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
- $exceptions = $response->getException();
- $exception = $exceptions[0];
- $exceptionType = get_class($exception);
- $error->exception = $exception;
- switch ($exceptionType) {
- case 'Zend_Controller_Router_Exception':
- if (404 == $exception->getCode()) {
- $error->type = self::EXCEPTION_NO_ROUTE;
- } else {
- $error->type = self::EXCEPTION_OTHER;
- }
- break;
- case 'Zend_Controller_Dispatcher_Exception':
- $error->type = self::EXCEPTION_NO_CONTROLLER;
- break;
- case 'Zend_Controller_Action_Exception':
- if (404 == $exception->getCode()) {
- $error->type = self::EXCEPTION_NO_ACTION;
- } else {
- $error->type = self::EXCEPTION_OTHER;
- }
- break;
- case 'Zend_Acl_Exception':
- $error->type = self::EXCEPTION_ACL;
- default:
- $error->type = self::EXCEPTION_OTHER;
- break;
- }
- // Keep a copy of the original request
- $error->request = clone $request;
- // get a count of the number of exceptions encountered
- $this->_exceptionCountAtFirstEncounter = count($exceptions);
- // Forward to the error handler
- $request->setParam('error_handler', $error)
- ->setModuleName($this->getErrorHandlerModule())
- ->setControllerName($this->getErrorHandlerController())
- ->setActionName($this->getErrorHandlerAction())
- ->setDispatched(false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement