Browse Source

Update arguments of Controller::beforeRedirect()

It now expects the same args as RequestHandler::beforeRedirect().
ADmad 11 years ago
parent
commit
10e54a14e2
2 changed files with 7 additions and 7 deletions
  1. 3 3
      src/Controller/Controller.php
  2. 4 4
      tests/TestCase/Controller/ControllerTest.php

+ 3 - 3
src/Controller/Controller.php

@@ -528,7 +528,7 @@ class Controller implements EventListener {
 			$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 @@ class Controller implements EventListener {
  * @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) {
 	}
 
 /**

+ 4 - 4
tests/TestCase/Controller/ControllerTest.php

@@ -439,11 +439,11 @@ class ControllerTest extends TestCase {
 		$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 @@ class ControllerTest extends TestCase {
 		$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 @@ class ControllerTest extends TestCase {
 		$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');