Skip to content

Commit 29602ef

Browse files
committed
Component::redirect() first parameter $code is deprecated (BC break)
1 parent eef70e0 commit 29602ef

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
@@ -314,20 +314,21 @@ public function isLinkCurrent(string $destination = NULL, $args = []): bool
314314

315315
/**
316316
* Redirect to another presenter, action or signal.
317-
* @param int [optional] HTTP error code
318317
* @param string destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
319318
* @param array|mixed
320319
* @throws Nette\Application\AbortException
321320
*/
322321
public function redirect($code, $destination = NULL, $args = []): void
323322
{
324-
if (!is_numeric($code)) { // first parameter is optional
323+
if (is_numeric($code)) {
324+
trigger_error(__METHOD__ . '() first parameter $code is deprecated; use redirectPermanent() for 301 redirect.', E_USER_DEPRECATED);
325+
if (func_num_args() > 3 || !is_array($args)) {
326+
$args = array_slice(func_get_args(), 2);
327+
}
328+
} elseif (!is_numeric($code)) { // first parameter is optional
325329
$args = func_num_args() < 3 && is_array($destination) ? $destination : array_slice(func_get_args(), 1);
326330
$destination = $code;
327331
$code = NULL;
328-
329-
} elseif (func_num_args() > 3 || !is_array($args)) {
330-
$args = array_slice(func_get_args(), 2);
331332
}
332333

333334
$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)