Skip to content

Commit

Permalink
Update arguments of Controller::beforeRedirect()
Browse files Browse the repository at this point in the history
It now expects the same args as RequestHandler::beforeRedirect().
  • Loading branch information
ADmad committed Jun 22, 2014
1 parent cca668e commit 10e54a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/Controller/Controller.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/TestCase/Controller/ControllerTest.php
Expand Up @@ -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());
}
Expand All @@ -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');

Expand All @@ -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');

Expand Down

0 comments on commit 10e54a1

Please sign in to comment.