Skip to content

Commit 173f387

Browse files
committed
Component::link() & etc uses variadic parameter
1 parent a46e3d7 commit 173f387

1 file changed

Lines changed: 25 additions & 25 deletions

File tree

src/Application/UI/Component.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,15 @@ public static function formatSignalMethod(string $signal): string
243243
/**
244244
* Generates URL to presenter, action or signal.
245245
* @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
246-
* @param array|mixed $args
246+
* @param mixed ...$args
247247
* @throws InvalidLinkException
248248
*/
249-
public function link(string $destination, $args = []): string
249+
public function link(string $destination, ...$args): string
250250
{
251251
try {
252-
$args = func_num_args() < 3 && is_array($args)
253-
? $args
254-
: array_slice(func_get_args(), 1);
252+
$args = count($args) === 1 && is_array($args[0] ?? null)
253+
? $args[0]
254+
: $args;
255255
return $this->getPresenter()->createRequest($this, $destination, $args, 'link');
256256

257257
} catch (InvalidLinkException $e) {
@@ -263,29 +263,29 @@ public function link(string $destination, $args = []): string
263263
/**
264264
* Returns destination as Link object.
265265
* @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
266-
* @param array|mixed $args
266+
* @param mixed ...$args
267267
*/
268-
public function lazyLink(string $destination, $args = []): Link
268+
public function lazyLink(string $destination, ...$args): Link
269269
{
270-
$args = func_num_args() < 3 && is_array($args)
271-
? $args
272-
: array_slice(func_get_args(), 1);
270+
$args = count($args) === 1 && is_array($args[0] ?? null)
271+
? $args[0]
272+
: $args;
273273
return new Link($this, $destination, $args);
274274
}
275275

276276

277277
/**
278278
* Determines whether it links to the current page.
279279
* @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
280-
* @param array|mixed $args
280+
* @param mixed ...$args
281281
* @throws InvalidLinkException
282282
*/
283-
public function isLinkCurrent(?string $destination = null, $args = []): bool
283+
public function isLinkCurrent(?string $destination = null, ...$args): bool
284284
{
285285
if ($destination !== null) {
286-
$args = func_num_args() < 3 && is_array($args)
287-
? $args
288-
: array_slice(func_get_args(), 1);
286+
$args = count($args) === 1 && is_array($args[0] ?? null)
287+
? $args[0]
288+
: $args;
289289
$this->getPresenter()->createRequest($this, $destination, $args, 'test');
290290
}
291291

@@ -296,14 +296,14 @@ public function isLinkCurrent(?string $destination = null, $args = []): bool
296296
/**
297297
* Redirect to another presenter, action or signal.
298298
* @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
299-
* @param array|mixed $args
299+
* @param mixed ...$args
300300
* @throws Nette\Application\AbortException
301301
*/
302-
public function redirect(string $destination, $args = []): void
302+
public function redirect(string $destination, ...$args): void
303303
{
304-
$args = func_num_args() < 3 && is_array($args)
305-
? $args
306-
: array_slice(func_get_args(), 1);
304+
$args = count($args) === 1 && is_array($args[0] ?? null)
305+
? $args[0]
306+
: $args;
307307
$presenter = $this->getPresenter();
308308
$presenter->redirectUrl($presenter->createRequest($this, $destination, $args, 'redirect'));
309309
}
@@ -312,14 +312,14 @@ public function redirect(string $destination, $args = []): void
312312
/**
313313
* Permanently redirects to presenter, action or signal.
314314
* @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
315-
* @param array|mixed $args
315+
* @param mixed ...$args
316316
* @throws Nette\Application\AbortException
317317
*/
318-
public function redirectPermanent(string $destination, $args = []): void
318+
public function redirectPermanent(string $destination, ...$args): void
319319
{
320-
$args = func_num_args() < 3 && is_array($args)
321-
? $args
322-
: array_slice(func_get_args(), 1);
320+
$args = count($args) === 1 && is_array($args[0] ?? null)
321+
? $args[0]
322+
: $args;
323323
$presenter = $this->getPresenter();
324324
$presenter->redirectUrl(
325325
$presenter->createRequest($this, $destination, $args, 'redirect'),

0 commit comments

Comments
 (0)