supernova-ws /
SuperNova
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Created by Gorlum 21.08.2016 13:33 |
||
| 4 | */ |
||
| 5 | |||
| 6 | namespace Common; |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Class Invoker |
||
| 10 | * |
||
| 11 | * Invoker incapsulates callable until PHP 5.4+ |
||
| 12 | * |
||
| 13 | * Supports method callable (2 element array), function callable (string) and lambda-functions |
||
| 14 | * |
||
| 15 | * @package Common |
||
| 16 | * @deprecated |
||
| 17 | */ |
||
| 18 | |||
| 19 | class Invoker { |
||
| 20 | |||
| 21 | protected $callable; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Invoker constructor. |
||
| 25 | * |
||
| 26 | * @param callable|null $callable |
||
| 27 | */ |
||
| 28 | 1 | public function __construct($callable) { |
|
| 29 | 1 | $this->callable = $callable; |
|
| 30 | 1 | } |
|
| 31 | |||
| 32 | /** |
||
| 33 | * @param mixed $callable |
||
| 34 | * |
||
| 35 | * @return static |
||
| 36 | */ |
||
| 37 | 1 | public static function build($callable) { |
|
| 38 | 1 | if (is_array($callable) && count($callable) == 2 && is_object($callable[0])) { |
|
| 39 | 1 | return new static($callable); |
|
| 40 | 1 | } elseif (is_string($callable) && function_exists($callable)) { |
|
| 41 | 1 | return new static($callable); |
|
| 42 | 1 | } elseif (is_callable($callable)) { |
|
| 43 | 1 | return new static($callable); |
|
| 44 | } else { |
||
| 45 | 1 | return new static(null); |
|
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | 1 | public function __invoke() { |
|
| 50 | 1 | return is_callable($this->callable) ? call_user_func_array($this->callable, func_get_args()) : null; |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 51 | } |
||
| 52 | |||
| 53 | } |
||
| 54 |