diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index 97474eaea..196f3553d 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -314,20 +314,21 @@ public function isLinkCurrent(string $destination = NULL, $args = []): bool /** * Redirect to another presenter, action or signal. - * @param int [optional] HTTP error code * @param string destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]" * @param array|mixed * @throws Nette\Application\AbortException */ 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());