From 3d71c31571b8c1d78f4884f714eac0713434b8fa Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 5 Jan 2021 23:55:00 +0100 Subject: [PATCH 1/2] added Callback::invokeAll() --- src/Utils/Callback.php | 13 ++++++++++ tests/Utils/Callback.invokeAll.phpt | 38 +++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 tests/Utils/Callback.invokeAll.phpt diff --git a/src/Utils/Callback.php b/src/Utils/Callback.php index 73d5cecd9..4631413d4 100644 --- a/src/Utils/Callback.php +++ b/src/Utils/Callback.php @@ -35,6 +35,19 @@ public static function closure($callable, string $method = null): \Closure } + /** + * Invokes all callables. + * @param callable[] $callables + */ + public static function invokeAll(array $callables, ...$args): array + { + foreach ($callables as $k => $cb) { + $callables[$k] = $cb(...$args); + } + return $callables; + } + + /** * Invokes callback. * @return mixed diff --git a/tests/Utils/Callback.invokeAll.phpt b/tests/Utils/Callback.invokeAll.phpt new file mode 100644 index 000000000..2edab06dc --- /dev/null +++ b/tests/Utils/Callback.invokeAll.phpt @@ -0,0 +1,38 @@ + Date: Fri, 7 Dec 2018 12:51:44 +0000 Subject: [PATCH 2/2] Arrays: added wrap() method (#180) --- src/Utils/Arrays.php | 15 +++++++++++ tests/Utils/Arrays.wrap().phpt | 46 ++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 tests/Utils/Arrays.wrap().phpt diff --git a/src/Utils/Arrays.php b/src/Utils/Arrays.php index ffbb7cb0e..df59a310f 100644 --- a/src/Utils/Arrays.php +++ b/src/Utils/Arrays.php @@ -343,4 +343,19 @@ public static function toKey($value) { return key([$value => null]); } + + + /** + * Returns copy of the $array where every item is converted to string + * and prefixed by $prefix and suffixed by $suffix. + * @return string[] + */ + public static function wrap(array $array, string $prefix = '', string $suffix = ''): array + { + $res = []; + foreach ($array as $k => $v) { + $res[$k] = $prefix . $v . $suffix; + } + return $res; + } } diff --git a/tests/Utils/Arrays.wrap().phpt b/tests/Utils/Arrays.wrap().phpt new file mode 100644 index 000000000..12af00e19 --- /dev/null +++ b/tests/Utils/Arrays.wrap().phpt @@ -0,0 +1,46 @@ +