From 6b07aee90b1b6e7153e97ab7f4743c19e1d5011d Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 25 Jan 2017 03:20:20 +0100 Subject: [PATCH] Component::redirect() first parameter $code is deprecated (BC break) --- src/Application/UI/Component.php | 10 ++++++---- tests/UI/Component.redirect().phpt | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index 348adeade..707f63eb8 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -316,13 +316,15 @@ public function isLinkCurrent(string $destination = NULL, $args = []): bool */ public function redirect($code, $destination = NULL, $args = []): void { - if (!is_numeric($code)) { // first parameter is optional + if (is_numeric($code)) { + trigger_error(__METHOD__ . '() first parameter $code is deprecated; use redirectPermanent() for 301 redirect.', E_USER_DEPRECATED); + if (func_num_args() > 3 || !is_array($args)) { + $args = array_slice(func_get_args(), 2); + } + } elseif (!is_numeric($code)) { // first parameter is optional $args = func_num_args() < 3 && is_array($destination) ? $destination : array_slice(func_get_args(), 1); $destination = $code; $code = NULL; - - } elseif (func_num_args() > 3 || !is_array($args)) { - $args = array_slice(func_get_args(), 2); } $presenter = $this->getPresenter(); diff --git a/tests/UI/Component.redirect().phpt b/tests/UI/Component.redirect().phpt index 65e34519c..258629666 100644 --- a/tests/UI/Component.redirect().phpt +++ b/tests/UI/Component.redirect().phpt @@ -65,7 +65,7 @@ test(function () use ($presenter) { test(function () use ($presenter) { - $presenter->redirect(301, 'foo', ['arg' => 1]); + @$presenter->redirect(301, 'foo', ['arg' => 1]); // @ is deprecated Assert::type(Nette\Application\Responses\RedirectResponse::class, $presenter->response); Assert::same(301, $presenter->response->getCode()); Assert::same('http://localhost/?arg=1&action=foo&presenter=test', $presenter->response->getUrl()); @@ -73,7 +73,7 @@ test(function () use ($presenter) { test(function () use ($presenter) { - $presenter->redirect(301, 'foo', 2); + @$presenter->redirect(301, 'foo', 2); // @ is deprecated Assert::type(Nette\Application\Responses\RedirectResponse::class, $presenter->response); Assert::same(301, $presenter->response->getCode()); Assert::same('http://localhost/?val=2&action=foo&presenter=test', $presenter->response->getUrl());