1 | <?php |
||
19 | class Delegate extends AbstractCallable |
||
20 | { |
||
21 | /** |
||
22 | * @var \ReflectionFunction|\ReflectionMethod |
||
23 | */ |
||
24 | private $reflection = null; |
||
25 | |||
26 | /** |
||
27 | * @var callable |
||
28 | */ |
||
29 | protected $target; |
||
30 | |||
31 | /** |
||
32 | * @param Closure $closure |
||
33 | * |
||
34 | * @return static |
||
35 | */ |
||
36 | public static function fromClosure(\Closure $closure) |
||
37 | { |
||
38 | return new static($closure); |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * @param object $object |
||
43 | * @param string $method |
||
44 | * |
||
45 | * @return static |
||
46 | */ |
||
47 | public static function fromMethod($object, $method) |
||
48 | { |
||
49 | return new static(array($object, $method)); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @param string $class |
||
54 | * @param string $method |
||
55 | * |
||
56 | * @return static |
||
57 | */ |
||
58 | public static function fromStaticMethod($class, $method) |
||
59 | { |
||
60 | return new static(array($class, $method)); |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * @param string $function |
||
65 | * |
||
66 | * @return static |
||
67 | */ |
||
68 | public static function fromFunction($function) |
||
69 | { |
||
70 | return new static($function); |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @param callable $target |
||
75 | */ |
||
76 | public function __construct($target) |
||
77 | { |
||
78 | if (!\is_callable($target)) { |
||
79 | throw new \InvalidArgumentException('The $target argument must be a callable.'); |
||
80 | } |
||
81 | |||
82 | if (\is_string($target) && \strpos($target, '::')) { |
||
83 | $target = explode('::', $target); |
||
84 | } |
||
85 | |||
86 | $this->target = $target; |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * @return \ReflectionFunction|\ReflectionMethod |
||
91 | */ |
||
92 | public function reflection() |
||
106 | |||
107 | /** |
||
108 | * @return callable |
||
109 | */ |
||
110 | public function target() |
||
111 | { |
||
114 | |||
115 | /** |
||
116 | * {@inheritdoc} |
||
117 | */ |
||
118 | protected function innerCallback() |
||
122 | } |
||
123 |