Skip to content

Commit 3d71c31

Browse files
committed
added Callback::invokeAll()
1 parent 745b477 commit 3d71c31

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/Utils/Callback.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ public static function closure($callable, string $method = null): \Closure
3535
}
3636

3737

38+
/**
39+
* Invokes all callables.
40+
* @param callable[] $callables
41+
*/
42+
public static function invokeAll(array $callables, ...$args): array
43+
{
44+
foreach ($callables as $k => $cb) {
45+
$callables[$k] = $cb(...$args);
46+
}
47+
return $callables;
48+
}
49+
50+
3851
/**
3952
* Invokes callback.
4053
* @return mixed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/**
4+
* Test: Nette\Utils\Callback::invokeAll()
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
use Nette\Utils\Callback;
10+
use Tester\Assert;
11+
12+
13+
require __DIR__ . '/../bootstrap.php';
14+
15+
16+
class Test
17+
{
18+
public function fn1(...$args)
19+
{
20+
return __METHOD__ . ' ' . implode(',', $args);
21+
}
22+
23+
24+
public function fn2(...$args)
25+
{
26+
return __METHOD__ . ' ' . implode(',', $args);
27+
}
28+
}
29+
30+
31+
$list = [];
32+
$list[] = [new Test, 'fn1'];
33+
$list[] = [new Test, 'fn2'];
34+
35+
Assert::same(
36+
['Test::fn1 a,b', 'Test::fn2 a,b'],
37+
Callback::invokeAll($list, 'a', 'b')
38+
);

0 commit comments

Comments
 (0)