From 10e54a14e2f34998753143a2e87bda0978a7b85c Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 22 Jun 2014 13:14:47 +0530 Subject: [PATCH] Update arguments of Controller::beforeRedirect() It now expects the same args as RequestHandler::beforeRedirect(). --- src/Controller/Controller.php | 6 +++--- tests/TestCase/Controller/ControllerTest.php | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Controller/Controller.php b/src/Controller/Controller.php index 3071bc1fedf..26a3c6f2a45 100644 --- a/src/Controller/Controller.php +++ b/src/Controller/Controller.php @@ -528,7 +528,7 @@ public function redirect($url, $status = null) { $response->statusCode($status); } - $event = new Event('Controller.beforeRedirect', $this, [$response, $url, $status]); + $event = new Event('Controller.beforeRedirect', $this, [$url, $response]); $event = $this->eventManager()->dispatch($event); if ($event->result instanceof Response) { return $event->result; @@ -690,11 +690,11 @@ public function beforeRender(Event $event) { * @param Event $event An Event instance * @param string|array $url A string or array-based URL pointing to another location within the app, * or an absolute URL - * @param int $status Optional HTTP status code (eg: 404) + * @param \Cake\Network\Response $response The response object. * @return void * @link http://book.cakephp.org/2.0/en/controllers.html#request-life-cycle-callbacks */ - public function beforeRedirect(Event $event, $url, $status = null) { + public function beforeRedirect(Event $event, $url, Response $response) { } /** diff --git a/tests/TestCase/Controller/ControllerTest.php b/tests/TestCase/Controller/ControllerTest.php index aad4d1a4108..fff675c889e 100644 --- a/tests/TestCase/Controller/ControllerTest.php +++ b/tests/TestCase/Controller/ControllerTest.php @@ -439,11 +439,11 @@ public function testRedirectBeforeRedirectModifyingUrl() { $Controller = new Controller(null); $Controller->response = new Response(); - $Controller->eventManager()->attach(function ($event, $response, $url) { + $Controller->eventManager()->attach(function ($event, $url, $response) { $response->location('http://book.cakephp.org'); }, 'Controller.beforeRedirect'); - $response = $Controller->redirect('http://cakephp.org', 301, false); + $response = $Controller->redirect('http://cakephp.org', 301); $this->assertEquals('http://book.cakephp.org', $response->header()['Location']); $this->assertEquals(301, $response->statusCode()); } @@ -457,7 +457,7 @@ public function testRedirectBeforeRedirectModifyingStatusCode() { $Response = $this->getMock('Cake\Network\Response', array('stop')); $Controller = new Controller(null, $Response); - $Controller->eventManager()->attach(function ($event, $response, $url) { + $Controller->eventManager()->attach(function ($event, $url, $response) { $response->statusCode(302); }, 'Controller.beforeRedirect'); @@ -476,7 +476,7 @@ public function testRedirectBeforeRedirectListenerReturnFalse() { $Response = $this->getMock('Cake\Network\Response', array('stop', 'header')); $Controller = new Controller(null, $Response); - $Controller->eventManager()->attach(function ($event, $response, $url, $status) { + $Controller->eventManager()->attach(function ($event, $url, $response) { return false; }, 'Controller.beforeRedirect');