Skip to content

Commit 3cb17fe

Browse files
committed
Component::link() & etc uses variadic parameter
1 parent 94c188d commit 3cb17fe

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

src/Application/UI/Component.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,15 @@ public static function formatSignalMethod(string $signal): string
249249
/**
250250
* Generates URL to presenter, action or signal.
251251
* @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
252-
* @param array|mixed $args
252+
* @param mixed ...$args
253253
* @throws InvalidLinkException
254254
*/
255-
public function link(string $destination, $args = []): string
255+
public function link(string $destination, ...$args): string
256256
{
257257
try {
258-
$args = func_num_args() < 3 && is_array($args)
259-
? $args
260-
: array_slice(func_get_args(), 1);
258+
$args = count($args) === 1 && is_array($args[0] ?? null)
259+
? $args[0]
260+
: $args;
261261
return $this->getPresenter()->createRequest($this, $destination, $args, 'link');
262262

263263
} catch (InvalidLinkException $e) {
@@ -269,29 +269,29 @@ public function link(string $destination, $args = []): string
269269
/**
270270
* Returns destination as Link object.
271271
* @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
272-
* @param array|mixed $args
272+
* @param mixed ...$args
273273
*/
274-
public function lazyLink(string $destination, $args = []): Link
274+
public function lazyLink(string $destination, ...$args): Link
275275
{
276-
$args = func_num_args() < 3 && is_array($args)
277-
? $args
278-
: array_slice(func_get_args(), 1);
276+
$args = count($args) === 1 && is_array($args[0] ?? null)
277+
? $args[0]
278+
: $args;
279279
return new Link($this, $destination, $args);
280280
}
281281

282282

283283
/**
284284
* Determines whether it links to the current page.
285285
* @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
286-
* @param array|mixed $args
286+
* @param mixed ...$args
287287
* @throws InvalidLinkException
288288
*/
289-
public function isLinkCurrent(?string $destination = null, $args = []): bool
289+
public function isLinkCurrent(?string $destination = null, ...$args): bool
290290
{
291291
if ($destination !== null) {
292-
$args = func_num_args() < 3 && is_array($args)
293-
? $args
294-
: array_slice(func_get_args(), 1);
292+
$args = count($args) === 1 && is_array($args[0] ?? null)
293+
? $args[0]
294+
: $args;
295295
$this->getPresenter()->createRequest($this, $destination, $args, 'test');
296296
}
297297

@@ -302,14 +302,14 @@ public function isLinkCurrent(?string $destination = null, $args = []): bool
302302
/**
303303
* Redirect to another presenter, action or signal.
304304
* @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
305-
* @param array|mixed $args
305+
* @param mixed ...$args
306306
* @throws Nette\Application\AbortException
307307
*/
308-
public function redirect(string $destination, $args = []): never
308+
public function redirect(string $destination, ...$args): never
309309
{
310-
$args = func_num_args() < 3 && is_array($args)
311-
? $args
312-
: array_slice(func_get_args(), 1);
310+
$args = count($args) === 1 && is_array($args[0] ?? null)
311+
? $args[0]
312+
: $args;
313313
$presenter = $this->getPresenter();
314314
$presenter->redirectUrl($presenter->createRequest($this, $destination, $args, 'redirect'));
315315
}
@@ -318,14 +318,14 @@ public function redirect(string $destination, $args = []): never
318318
/**
319319
* Permanently redirects to presenter, action or signal.
320320
* @param string $destination in format "[//] [[[module:]presenter:]action | signal! | this] [#fragment]"
321-
* @param array|mixed $args
321+
* @param mixed ...$args
322322
* @throws Nette\Application\AbortException
323323
*/
324-
public function redirectPermanent(string $destination, $args = []): never
324+
public function redirectPermanent(string $destination, ...$args): never
325325
{
326-
$args = func_num_args() < 3 && is_array($args)
327-
? $args
328-
: array_slice(func_get_args(), 1);
326+
$args = count($args) === 1 && is_array($args[0] ?? null)
327+
? $args[0]
328+
: $args;
329329
$presenter = $this->getPresenter();
330330
$presenter->redirectUrl(
331331
$presenter->createRequest($this, $destination, $args, 'redirect'),

0 commit comments

Comments
 (0)