Skip to content

Commit b38ee7c

Browse files
committed
Component::link() & etc uses variadic parameter
1 parent a4bc74f commit b38ee7c

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

src/Application/UI/Component.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace Nette\Application\UI;
1111

1212
use Nette;
13-
use function array_key_exists, array_slice, func_get_arg, func_get_args, func_num_args, get_debug_type, is_array, link, method_exists, sprintf, trigger_error;
13+
use function array_key_exists, count, func_get_arg, func_num_args, get_debug_type, is_array, link, method_exists, sprintf, trigger_error;
1414

1515

1616
/**
@@ -291,15 +291,15 @@ public static function formatSignalMethod(string $signal): string
291291
/**
292292
* Generates URL to presenter, action or signal.
293293
* @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
294-
* @param array|mixed $args
294+
* @param mixed ...$args
295295
* @throws InvalidLinkException
296296
*/
297-
public function link(string $destination, $args = []): string
297+
public function link(string $destination, ...$args): string
298298
{
299299
try {
300-
$args = func_num_args() < 3 && is_array($args)
301-
? $args
302-
: array_slice(func_get_args(), 1);
300+
$args = count($args) === 1 && is_array($args[0] ?? null)
301+
? $args[0]
302+
: $args;
303303
return $this->getPresenter()->getLinkGenerator()->link($destination, $args, $this, 'link');
304304

305305
} catch (InvalidLinkException $e) {
@@ -311,29 +311,29 @@ public function link(string $destination, $args = []): string
311311
/**
312312
* Returns destination as Link object.
313313
* @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
314-
* @param array|mixed $args
314+
* @param mixed ...$args
315315
*/
316-
public function lazyLink(string $destination, $args = []): Link
316+
public function lazyLink(string $destination, ...$args): Link
317317
{
318-
$args = func_num_args() < 3 && is_array($args)
319-
? $args
320-
: array_slice(func_get_args(), 1);
318+
$args = count($args) === 1 && is_array($args[0] ?? null)
319+
? $args[0]
320+
: $args;
321321
return new Link($this, $destination, $args);
322322
}
323323

324324

325325
/**
326326
* Determines whether it links to the current page.
327327
* @param ?string $destination in format "[[[module:]presenter:]action | signal! | this]"
328-
* @param array|mixed $args
328+
* @param mixed ...$args
329329
* @throws InvalidLinkException
330330
*/
331-
public function isLinkCurrent(?string $destination = null, $args = []): bool
331+
public function isLinkCurrent(?string $destination = null, ...$args): bool
332332
{
333333
if ($destination !== null) {
334-
$args = func_num_args() < 3 && is_array($args)
335-
? $args
336-
: array_slice(func_get_args(), 1);
334+
$args = count($args) === 1 && is_array($args[0] ?? null)
335+
? $args[0]
336+
: $args;
337337
$this->getPresenter()->getLinkGenerator()->createRequest($this, $destination, $args, 'test');
338338
}
339339

@@ -344,14 +344,14 @@ public function isLinkCurrent(?string $destination = null, $args = []): bool
344344
/**
345345
* Redirect to another presenter, action or signal.
346346
* @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
347-
* @param array|mixed $args
347+
* @param mixed ...$args
348348
* @throws Nette\Application\AbortException
349349
*/
350-
public function redirect(string $destination, $args = []): never
350+
public function redirect(string $destination, ...$args): never
351351
{
352-
$args = func_num_args() < 3 && is_array($args)
353-
? $args
354-
: array_slice(func_get_args(), 1);
352+
$args = count($args) === 1 && is_array($args[0] ?? null)
353+
? $args[0]
354+
: $args;
355355
$presenter = $this->getPresenter();
356356
$presenter->saveGlobalState();
357357
$presenter->redirectUrl($presenter->getLinkGenerator()->link($destination, $args, $this, 'redirect'));
@@ -361,14 +361,14 @@ public function redirect(string $destination, $args = []): never
361361
/**
362362
* Permanently redirects to presenter, action or signal.
363363
* @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
364-
* @param array|mixed $args
364+
* @param mixed ...$args
365365
* @throws Nette\Application\AbortException
366366
*/
367-
public function redirectPermanent(string $destination, $args = []): never
367+
public function redirectPermanent(string $destination, ...$args): never
368368
{
369-
$args = func_num_args() < 3 && is_array($args)
370-
? $args
371-
: array_slice(func_get_args(), 1);
369+
$args = count($args) === 1 && is_array($args[0] ?? null)
370+
? $args[0]
371+
: $args;
372372
$presenter = $this->getPresenter();
373373
$presenter->redirectUrl(
374374
$presenter->getLinkGenerator()->link($destination, $args, $this, 'redirect'),

0 commit comments

Comments
 (0)