Skip to content

Commit

Permalink
Allow all controller/component callbacks to return response instance.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Apr 29, 2014
1 parent 7f2d681 commit f3efae7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/Controller/Controller.php
Expand Up @@ -511,10 +511,13 @@ public function setEventManager($eventManager) {
* - Calls the controller `beforeFilter`.
* - triggers Component `startup` methods.
*
* @return void
* @return void|\Cake\Network\Response
*/
public function startupProcess() {
$this->getEventManager()->dispatch(new Event('Controller.initialize', $this));
$result = $this->getEventManager()->dispatch(new Event('Controller.initialize', $this));
if ($result instanceof Response) {
return $result;
}
$result = $this->getEventManager()->dispatch(new Event('Controller.startup', $this));
if ($result instanceof Response) {
return $result;
Expand All @@ -528,10 +531,13 @@ public function startupProcess() {
* - triggers the component `shutdown` callback.
* - calls the Controller's `afterFilter` method.
*
* @return void
* @return void|\Cake\Network\Response
*/
public function shutdownProcess() {
$this->getEventManager()->dispatch(new Event('Controller.shutdown', $this));
$result = $this->getEventManager()->dispatch(new Event('Controller.shutdown', $this));
if ($result instanceof Response) {
return $result;
}
}

/**
Expand Down Expand Up @@ -597,7 +603,11 @@ public function setAction($action) {
*/
public function render($view = null, $layout = null) {
$event = new Event('Controller.beforeRender', $this);
$this->getEventManager()->dispatch($event);
$result = $this->getEventManager()->dispatch($event);
if ($result instanceof Response) {
$this->autoRender = false;
return $result;
}
if ($event->isStopped()) {
$this->autoRender = false;
return $this->response;
Expand Down
6 changes: 5 additions & 1 deletion src/Routing/Dispatcher.php
Expand Up @@ -203,7 +203,11 @@ protected function _invoke(Controller $controller) {
$response = $controller->response;
}

$controller->shutdownProcess();
$result = $controller->shutdownProcess();
if ($result instanceof Response) {
return $result;
}

return $response;
}

Expand Down

0 comments on commit f3efae7

Please sign in to comment.