Skip to content

Commit 04c39c3

Browse files
authored
Update Helper.php
1 parent 80f0c24 commit 04c39c3

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/Helper.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -199,25 +199,26 @@ public static function getValueOfArray(array $array, $key, $default = null)
199199
* @param array $args
200200
* @return mixed
201201
*/
202-
public static function call($cb, array $args = [])
202+
public static function call($cb, ...$args)
203203
{
204-
$args = array_values($args);
205-
206-
if (
207-
(is_object($cb) && method_exists($cb, '__invoke')) ||
208-
(is_string($cb) && function_exists($cb))
209-
) {
210-
$ret = $cb(...$args);
211-
} elseif (is_array($cb)) {
204+
if (is_string($cb)) {
205+
// function
206+
if (strpos($cb, '::') === false) {
207+
return $cb(...$args);
208+
}
209+
210+
// ClassName/Service::method
211+
$cb = explode('::', $cb, 2);
212+
} elseif (is_object($cb) && method_exists($cb, '__invoke')) {
213+
return $cb(...$args);
214+
}
215+
216+
if (is_array($cb)) {
212217
list($obj, $mhd) = $cb;
213218

214-
$ret = is_object($obj) ? $obj->$mhd(...$args) : $obj::$mhd(...$args);
215-
} elseif (method_exists('Swoole\Coroutine', 'call_user_func_array')) {
216-
$ret = \Swoole\Coroutine::call_user_func_array($cb, $args);
217-
} else {
218-
$ret = call_user_func_array($cb, $args);
219+
return is_object($obj) ? $obj->$mhd(...$args) : $obj::$mhd(...$args);
219220
}
220221

221-
return $ret;
222+
throw new \InvalidArgumentException('The parameter is not a callable');
222223
}
223224
}

0 commit comments

Comments
 (0)