Skip to content

Commit

Permalink
Component::redirect() first parameter $code is deprecated (BC break)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 25, 2017
1 parent c6a5b20 commit 6b07aee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/Application/UI/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions tests/UI/Component.redirect().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ 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());
});


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());
Expand Down

0 comments on commit 6b07aee

Please sign in to comment.