Skip to content
This repository was archived by the owner on Jan 23, 2019. It is now read-only.

Commit d810baf

Browse files
committed
change PhpHelper::call args use method
1 parent f3e4f46 commit d810baf

File tree

7 files changed

+27
-24
lines changed

7 files changed

+27
-24
lines changed

src/Components/DeferredCallable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __invoke(...$args)
3737
$callable = $this->callable;
3838

3939
if (is_callable($callable)) {
40-
return PhpHelper::call($callable, $args);
40+
return PhpHelper::call($callable, ...$args);
4141
}
4242

4343
if (is_string($callable) && class_exists($callable)) {

src/Components/ErrorHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public function handleError($code, $message, $file = '', $line = 0, array $conte
203203
}
204204

205205
if ($this->previousErrorHandler) {
206-
return PhpHelper::call($this->previousErrorHandler, [$code, $message, $file, $line, $context]);
206+
return PhpHelper::call($this->previousErrorHandler, $code, $message, $file, $line, $context);
207207
}
208208

209209
return false;

src/Helpers/PhpHelper.php

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,32 @@ class PhpHelper extends EnvHelper
1616
{
1717
/**
1818
* @param $cb
19-
* @param array $args
19+
* @param array ...$args
2020
* @return mixed
2121
*/
22-
public static function call($cb, array $args = [])
22+
public static function call($cb, ...$args)
2323
{
24-
$args = array_values($args);
25-
26-
if (
27-
(is_object($cb) && method_exists($cb, '__invoke')) ||
28-
(is_string($cb) && function_exists($cb))
29-
) {
30-
$ret = $cb(...$args);
31-
} elseif (is_array($cb)) {
24+
// $args = array_values($args);
25+
26+
if (is_string($cb)) {
27+
// function
28+
if (strpos($cb, '::') === false) {
29+
return $cb(...$args);
30+
}
31+
32+
// ClassName/Service::method
33+
$cb = explode('::', $cb, 2);
34+
} elseif (is_object($cb) && method_exists($cb, '__invoke')) {
35+
return $cb(...$args);
36+
}
37+
38+
if (is_array($cb)) {
3239
list($obj, $mhd) = $cb;
3340

34-
$ret = is_object($obj) ? $obj->$mhd(...$args) : $obj::$mhd(...$args);
35-
} elseif (class_exists(Coroutine::class, false)) {
36-
$ret = Coroutine::call_user_func_array($cb, $args);
37-
} else {
38-
$ret = call_user_func_array($cb, $args);
41+
return is_object($obj) ? $obj->$mhd(...$args) : $obj::$mhd(...$args);
3942
}
4043

41-
return $ret;
44+
throw new \InvalidArgumentException('The parameter is not a callable');
4245
}
4346

4447
/**

src/Traits/AopProxyAwareTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@ public function call($method, array $args = [])
5858
// on before exec method
5959
if ($cbList = $this->findProxyCallback($target, $method)) {
6060
foreach ($cbList as $cb) {
61-
PhpHelper::call($cb, [$target, $method, $args]);
61+
PhpHelper::call($cb, $target, $method, $args);
6262
}
6363
}
6464

6565
// exec method
66-
$ret = PhpHelper::call([$target, $method], $args);
66+
$ret = PhpHelper::call([$target, $method], ...$args);
6767

6868
// on after exec method
6969
if ($cb = $this->findProxyCallback($target, $method, 'after')) {
7070
foreach ($cbList as $cb) {
71-
PhpHelper::call($cb, [$target, $method, $args]);
71+
PhpHelper::call($cb, $target, $method, $args);
7272
}
7373
}
7474

src/Traits/EventTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function fire($event, array $args = [])
7676
// call event handlers of the event.
7777
foreach ((array)$this->eventHandlers[$event] as $cb) {
7878
// return FALSE to stop go on handle.
79-
if (false === PhpHelper::call($cb, $args)) {
79+
if (false === PhpHelper::call($cb, ...$args)) {
8080
break;
8181
}
8282
}

src/Traits/FixedEventStaticTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static function fire($event, array $args = [])
8080
// call event handlers of the event.
8181
foreach ((array)self::$eventHandlers[$event] as $cb) {
8282
// return FALSE to stop go on handle.
83-
if (false === PhpHelper::call($cb, $args)) {
83+
if (false === PhpHelper::call($cb, ...$args)) {
8484
break;
8585
}
8686
}

src/Traits/FixedEventTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ protected function fire(string $event, array $args = [])
150150
return null;
151151
}
152152

153-
return PhpHelper::call($cb, $args);
153+
return PhpHelper::call($cb, ...$args);
154154
}
155155

156156
}

0 commit comments

Comments
 (0)