1 | <?php |
||
21 | abstract class AbstractMethodInvocation extends AbstractInvocation implements MethodInvocation |
||
22 | { |
||
23 | |||
24 | /** |
||
25 | * Instance of object for invoking or class name for static call |
||
26 | * |
||
27 | * @var object|string |
||
28 | */ |
||
29 | protected $instance; |
||
30 | |||
31 | /** |
||
32 | * Instance of reflection method for class |
||
33 | * |
||
34 | * @var ReflectionMethod |
||
35 | */ |
||
36 | protected $reflectionMethod; |
||
37 | |||
38 | /** |
||
39 | * Name of the invocation class |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $className = ''; |
||
44 | |||
45 | /** |
||
46 | * Constructor for method invocation |
||
47 | * |
||
48 | * @param string $className Class name |
||
49 | * @param string $methodName Method to invoke |
||
50 | * @param $advices array List of advices for this invocation |
||
51 | */ |
||
52 | 22 | public function __construct(string $className, string $methodName, array $advices) |
|
63 | |||
64 | /** |
||
65 | * Invokes current method invocation with all interceptors |
||
66 | * |
||
67 | * @param null|object|string $instance Invocation instance (class name for static methods) |
||
68 | * @param array $arguments List of arguments for method invocation |
||
69 | * @param array $variadicArguments Additional list of variadic arguments |
||
70 | * |
||
71 | * @return mixed Result of invocation |
||
72 | */ |
||
73 | 20 | final public function __invoke($instance = null, array $arguments = [], array $variadicArguments = []) |
|
74 | { |
||
75 | 20 | if ($this->level > 0) { |
|
76 | 2 | $this->stackFrames[] = [$this->arguments, $this->instance, $this->current]; |
|
77 | } |
||
78 | |||
79 | 20 | if (!empty($variadicArguments)) { |
|
80 | $arguments = \array_merge($arguments, $variadicArguments); |
||
81 | } |
||
82 | |||
83 | try { |
||
84 | 20 | ++$this->level; |
|
85 | |||
86 | 20 | $this->current = 0; |
|
87 | 20 | $this->instance = $instance; |
|
88 | 20 | $this->arguments = $arguments; |
|
89 | |||
90 | 20 | return $this->proceed(); |
|
91 | } finally { |
||
92 | 20 | --$this->level; |
|
93 | |||
94 | 20 | if ($this->level > 0) { |
|
95 | 20 | list($this->arguments, $this->instance, $this->current) = \array_pop($this->stackFrames); |
|
96 | } |
||
97 | } |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * Gets the method being called. |
||
102 | * |
||
103 | * @return ReflectionMethod|AnnotatedReflectionMethod the method being called. |
||
104 | */ |
||
105 | 2 | public function getMethod(): ReflectionMethod |
|
109 | |||
110 | /** |
||
111 | * Returns the object that holds the current joinpoint's static |
||
112 | * part. |
||
113 | * |
||
114 | * @return object|string the object for dynamic call or string with name of scope |
||
115 | */ |
||
116 | public function getThis() |
||
120 | |||
121 | /** |
||
122 | * Returns the static part of this joinpoint. |
||
123 | * |
||
124 | * @return object |
||
125 | */ |
||
126 | 1 | public function getStaticPart() |
|
130 | |||
131 | /** |
||
132 | * Returns friendly description of this joinpoint |
||
133 | * |
||
134 | * @return string |
||
135 | */ |
||
136 | final public function __toString() |
||
145 | } |
||
146 |