Skip to content

Commit d4ef38e

Browse files
committed
Component::redirect() first parameter $code is deprecated (BC break)
1 parent ecbb60f commit d4ef38e

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/Application/UI/Component.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,20 +309,21 @@ public function isLinkCurrent(string $destination = NULL, $args = []): bool
309309

310310
/**
311311
* Redirect to another presenter, action or signal.
312-
* @param int [optional] HTTP error code
313312
* @param string destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
314313
* @param array|mixed
315314
* @throws Nette\Application\AbortException
316315
*/
317316
public function redirect($code, $destination = NULL, $args = []): void
318317
{
319-
if (!is_numeric($code)) { // first parameter is optional
318+
if (is_numeric($code)) {
319+
trigger_error(__METHOD__ . '() first parameter $code is deprecated; use redirectPermanent() for 301 redirect.', E_USER_DEPRECATED);
320+
if (func_num_args() > 3 || !is_array($args)) {
321+
$args = array_slice(func_get_args(), 2);
322+
}
323+
} elseif (!is_numeric($code)) { // first parameter is optional
320324
$args = func_num_args() < 3 && is_array($destination) ? $destination : array_slice(func_get_args(), 1);
321325
$destination = $code;
322326
$code = NULL;
323-
324-
} elseif (func_num_args() > 3 || !is_array($args)) {
325-
$args = array_slice(func_get_args(), 2);
326327
}
327328

328329
$presenter = $this->getPresenter();

tests/UI/Component.redirect().phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ test(function () use ($presenter) {
6565

6666

6767
test(function () use ($presenter) {
68-
$presenter->redirect(301, 'foo', ['arg' => 1]);
68+
@$presenter->redirect(301, 'foo', ['arg' => 1]); // @ is deprecated
6969
Assert::type(Nette\Application\Responses\RedirectResponse::class, $presenter->response);
7070
Assert::same(301, $presenter->response->getCode());
7171
Assert::same('http://localhost/?arg=1&action=foo&presenter=test', $presenter->response->getUrl());
7272
});
7373

7474

7575
test(function () use ($presenter) {
76-
$presenter->redirect(301, 'foo', 2);
76+
@$presenter->redirect(301, 'foo', 2); // @ is deprecated
7777
Assert::type(Nette\Application\Responses\RedirectResponse::class, $presenter->response);
7878
Assert::same(301, $presenter->response->getCode());
7979
Assert::same('http://localhost/?val=2&action=foo&presenter=test', $presenter->response->getUrl());

0 commit comments

Comments
 (0)