From bddff7d2b0c57d756b1ec1eadb3e7da7c8236622 Mon Sep 17 00:00:00 2001 From: Kim Biesbjerg Date: Wed, 13 Jul 2016 23:40:27 +0200 Subject: [PATCH] Dispatch afterDispatch event when exception is thrown --- lib/Cake/Error/ExceptionRenderer.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Error/ExceptionRenderer.php b/lib/Cake/Error/ExceptionRenderer.php index a245b64ee..40f551417 100644 --- a/lib/Cake/Error/ExceptionRenderer.php +++ b/lib/Cake/Error/ExceptionRenderer.php @@ -20,9 +20,12 @@ */ App::uses('Sanitize', 'Utility'); +App::uses('Dispatcher', 'Routing'); App::uses('Router', 'Routing'); -App::uses('CakeResponse', 'Network'); App::uses('Controller', 'Controller'); +App::uses('CakeRequest', 'Network'); +App::uses('CakeResponse', 'Network'); +App::uses('CakeEvent', 'Event'); /** * Exception Renderer. @@ -287,7 +290,7 @@ class ExceptionRenderer { protected function _outputMessage($template) { try { $this->controller->render($template); - $this->controller->afterFilter(); + $this->_shutdown(); $this->controller->response->send(); } catch (MissingViewException $e) { $attributes = $e->getAttributes(); @@ -327,4 +330,15 @@ class ExceptionRenderer { $this->controller->response->send(); } + protected function _shutdown() { + $this->controller->afterFilter(); + + $Dispatcher = new Dispatcher(); + $afterDispatchEvent = new CakeEvent('Dispatcher.afterDispatch', $Dispatcher, array( + 'request' => $this->controller->request, + 'response' => $this->controller->response + )); + $Dispatcher->getEventManager()->dispatch($afterDispatchEvent); + } + }