Skip to content

Commit

Permalink
Update Helper.php
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Nov 3, 2017
1 parent 80f0c24 commit 04c39c3
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,25 +199,26 @@ public static function getValueOfArray(array $array, $key, $default = null)
* @param array $args
* @return mixed
*/
public static function call($cb, array $args = [])
public static function call($cb, ...$args)
{
$args = array_values($args);

if (
(is_object($cb) && method_exists($cb, '__invoke')) ||
(is_string($cb) && function_exists($cb))
) {
$ret = $cb(...$args);
} elseif (is_array($cb)) {
if (is_string($cb)) {
// function
if (strpos($cb, '::') === false) {
return $cb(...$args);
}

// ClassName/Service::method
$cb = explode('::', $cb, 2);
} elseif (is_object($cb) && method_exists($cb, '__invoke')) {
return $cb(...$args);
}

if (is_array($cb)) {
list($obj, $mhd) = $cb;

$ret = is_object($obj) ? $obj->$mhd(...$args) : $obj::$mhd(...$args);
} elseif (method_exists('Swoole\Coroutine', 'call_user_func_array')) {
$ret = \Swoole\Coroutine::call_user_func_array($cb, $args);
} else {
$ret = call_user_func_array($cb, $args);
return is_object($obj) ? $obj->$mhd(...$args) : $obj::$mhd(...$args);
}

return $ret;
throw new \InvalidArgumentException('The parameter is not a callable');
}
}

0 comments on commit 04c39c3

Please sign in to comment.