Browse Source

Make Controller::redirect() return response object.

The $exit param has been removed and it no longer sends response and exits.
ADmad 12 years ago
parent
commit
0fbd3eca87

+ 0 - 4
src/Controller/Component/AuthComponent.php

@@ -1,9 +1,5 @@
 <?php
 /**
- * Authentication component
- *
- * Manages user logins and permissions.
- *
  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  *

+ 4 - 8
src/Controller/Controller.php

@@ -538,11 +538,10 @@ class Controller implements EventListener {
  * @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 bool $exit If true, exit() will be called after the redirect
- * @return void
- * @link http://book.cakephp.org/2.0/en/controllers.html#Controller::redirect
+ * @return void|\Cake\Network\Response
+ * @link http://book.cakephp.org/3.0/en/controllers.html#Controller::redirect
  */
-	public function redirect($url, $status = null, $exit = true) {
+	public function redirect($url, $status = null) {
 		$this->autoRender = false;
 
 		$response = $this->response;
@@ -560,10 +559,7 @@ class Controller implements EventListener {
 			$response->location(Router::url($url, true));
 		}
 
-		if ($exit) {
-			$response->send();
-			$response->stop();
-		}
+		return $response;
 	}
 
 /**

+ 11 - 10
tests/TestCase/Controller/ControllerTest.php

@@ -429,9 +429,9 @@ class ControllerTest extends TestCase {
 		$Controller = new Controller(null);
 		$Controller->response = new Response();
 
-		$Controller->redirect('http://cakephp.org', (int)$code, false);
-		$this->assertEquals($code, $Controller->response->statusCode());
-		$this->assertEquals('http://cakephp.org', $Controller->response->header()['Location']);
+		$response = $Controller->redirect('http://cakephp.org', (int)$code, false);
+		$this->assertEquals($code, $response->statusCode());
+		$this->assertEquals('http://cakephp.org', $response->header()['Location']);
 		$this->assertFalse($Controller->autoRender);
 	}
 
@@ -448,9 +448,9 @@ class ControllerTest extends TestCase {
 			$response->location('http://book.cakephp.org');
 		}, 'Controller.beforeRedirect');
 
-		$Controller->redirect('http://cakephp.org', 301, false);
-		$this->assertEquals('http://book.cakephp.org', $Controller->response->header()['Location']);
-		$this->assertEquals(301, $Controller->response->statusCode());
+		$response = $Controller->redirect('http://cakephp.org', 301, false);
+		$this->assertEquals('http://book.cakephp.org', $response->header()['Location']);
+		$this->assertEquals(301, $response->statusCode());
 	}
 
 /**
@@ -466,10 +466,10 @@ class ControllerTest extends TestCase {
 			$response->statusCode(302);
 		}, 'Controller.beforeRedirect');
 
-		$Controller->redirect('http://cakephp.org', 301, false);
+		$response = $Controller->redirect('http://cakephp.org', 301, false);
 
-		$this->assertEquals('http://cakephp.org', $Controller->response->header()['Location']);
-		$this->assertEquals(302, $Controller->response->statusCode());
+		$this->assertEquals('http://cakephp.org', $response->header()['Location']);
+		$this->assertEquals(302, $response->statusCode());
 	}
 
 /**
@@ -492,7 +492,8 @@ class ControllerTest extends TestCase {
 		$Controller->response->expects($this->never())
 			->method('statusCode');
 
-		$Controller->redirect('http://cakephp.org');
+		$result = $Controller->redirect('http://cakephp.org');
+		$this->assertNull($result);
 	}
 
 /**