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