1 | <?php |
||
21 | class ReflectionConstructorInvocation extends AbstractInvocation implements ConstructorInvocation |
||
22 | { |
||
23 | /** |
||
24 | * Reflection class |
||
25 | * |
||
26 | * @var ReflectionClass |
||
27 | */ |
||
28 | protected $class = null; |
||
29 | |||
30 | /** |
||
31 | * Instance of created class, can be used for Around or After types of advices |
||
32 | * |
||
33 | * @var object|null |
||
34 | */ |
||
35 | protected $instance = null; |
||
36 | |||
37 | /** |
||
38 | * Instance of reflection constructor for class |
||
39 | * |
||
40 | * @var null|ReflectionMethod |
||
41 | */ |
||
42 | private $constructor = null; |
||
43 | |||
44 | /** |
||
45 | * Number of constructor arguments |
||
46 | * |
||
47 | * @var int |
||
48 | */ |
||
49 | private $constructorArguments = 0; |
||
50 | |||
51 | /** |
||
52 | * Constructor for constructor invocation :) |
||
53 | * |
||
54 | * @param string $className Class name |
||
55 | * @param $advices array List of advices for this invocation |
||
56 | * @param string $type |
||
57 | */ |
||
58 | public function __construct($className, $type, array $advices) |
||
74 | |||
75 | /** |
||
76 | * Proceed to the next interceptor in the Chain |
||
77 | * |
||
78 | * Typically this method is called inside previous closure, as instance of Joinpoint is passed to callback |
||
79 | * Do not call this method directly, only inside callback closures. |
||
80 | * |
||
81 | * @return mixed |
||
82 | */ |
||
83 | final public function proceed() |
||
84 | { |
||
85 | if (isset($this->advices[$this->current])) { |
||
86 | /** @var $currentInterceptor Interceptor */ |
||
87 | $currentInterceptor = $this->advices[$this->current]; |
||
88 | $this->current++; |
||
89 | |||
90 | return $currentInterceptor->invoke($this); |
||
91 | } |
||
92 | |||
93 | if (!$this->constructorArguments) { |
||
94 | $this->instance = $this->class->newInstance(); |
||
95 | } else { |
||
96 | $this->instance = $this->class->newInstanceArgs($this->arguments); |
||
97 | } |
||
98 | |||
99 | return $this->instance; |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * Gets the constructor being called. |
||
104 | * |
||
105 | * @return ReflectionMethod|null the constructor being called or null if it is absent. |
||
106 | */ |
||
107 | public function getConstructor() |
||
111 | |||
112 | /** |
||
113 | * Returns the object that holds the current joinpoint's static |
||
114 | * part. |
||
115 | * |
||
116 | * @return object|null the object (can be null if the accessible object is |
||
117 | * static). |
||
118 | */ |
||
119 | public function getThis() |
||
123 | |||
124 | /** |
||
125 | * Returns the static part of this joinpoint. |
||
126 | * |
||
127 | * @return null|ReflectionMethod |
||
128 | */ |
||
129 | public function getStaticPart() |
||
133 | |||
134 | /** |
||
135 | * Invokes current constructor invocation with all interceptors |
||
136 | * |
||
137 | * @return mixed |
||
138 | */ |
||
139 | final public function __invoke(array $arguments = []) |
||
146 | |||
147 | /** |
||
148 | * Returns a friendly description of current joinpoint |
||
149 | * |
||
150 | * @return string |
||
151 | */ |
||
152 | final public function __toString() |
||
159 | } |
||
160 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.