1 | <?php |
||
5 | class Proxy |
||
6 | { |
||
7 | private $callable; |
||
8 | |||
9 | private $middlewares; |
||
10 | |||
11 | /** |
||
12 | * Proxy constructor. |
||
13 | * |
||
14 | * @param $callable |
||
15 | * @param $middlewares |
||
16 | */ |
||
17 | 10 | public function __construct($callable, $middlewares) |
|
22 | |||
23 | 10 | public function __call($method, $params) |
|
24 | { |
||
25 | 10 | $pipeline = new Pipeline(app()); |
|
26 | |||
27 | 10 | if (!is_string($this->callable)) { |
|
28 | // for method calls on objects. |
||
29 | $core = (function ($params) use ($method) { |
||
30 | try { |
||
31 | 4 | return $this->$method(...$params); |
|
32 | 1 | } catch (\Throwable $e) { |
|
33 | 1 | return $e; |
|
34 | } |
||
35 | 6 | })->bindTo($this->callable, $this->callable); |
|
36 | } else { |
||
37 | // for static method calls on classes. |
||
38 | $core = function ($params) use ($method) { |
||
39 | try { |
||
40 | 2 | return call_user_func_array([$this->callable, $method], $params); |
|
41 | 1 | } catch (\Throwable $e) { |
|
42 | 1 | return $e; |
|
43 | } |
||
44 | 4 | }; |
|
45 | } |
||
46 | |||
47 | 10 | return $this->sendItThroughPipes($params, $pipeline, $core); |
|
48 | } |
||
49 | |||
50 | /** |
||
51 | * @param $params |
||
52 | * @param Pipeline $pipeline |
||
53 | * @param \Closure $core |
||
54 | * |
||
55 | * @throws \Throwable |
||
56 | * @return mixed |
||
57 | */ |
||
58 | 10 | private function sendItThroughPipes($params, Pipeline $pipeline, \Closure $core) |
|
68 | } |
||
69 |