Skip to content

Commit b4f892f

Browse files
committed
Component::redirect() first parameter $code is deprecated (BC break)
1 parent 52ba64f commit b4f892f

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/Application/UI/Component.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,15 @@ public function isLinkCurrent(string $destination = NULL, $args = []): bool
316316
*/
317317
public function redirect($code, $destination = NULL, $args = []): void
318318
{
319-
if (!is_numeric($code)) { // first parameter is optional
319+
if (is_numeric($code)) {
320+
trigger_error(__METHOD__ . '() first parameter $code is deprecated; use redirectPermanent() for 301 redirect.', E_USER_DEPRECATED);
321+
if (func_num_args() > 3 || !is_array($args)) {
322+
$args = array_slice(func_get_args(), 2);
323+
}
324+
} elseif (!is_numeric($code)) { // first parameter is optional
320325
$args = func_num_args() < 3 && is_array($destination) ? $destination : array_slice(func_get_args(), 1);
321326
$destination = $code;
322327
$code = NULL;
323-
324-
} elseif (func_num_args() > 3 || !is_array($args)) {
325-
$args = array_slice(func_get_args(), 2);
326328
}
327329

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

tests/UI/Component.redirect().phpt

+2-2
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)