1 | <?php |
||
23 | class AdviceMatcher |
||
24 | { |
||
25 | /** |
||
26 | * Loader of aspects |
||
27 | * |
||
28 | * @var AspectLoader |
||
29 | */ |
||
30 | protected $loader; |
||
31 | |||
32 | /** |
||
33 | * Flag to enable/disable support of global function interception |
||
34 | * |
||
35 | * @var bool |
||
36 | */ |
||
37 | private $isInterceptFunctions = false; |
||
38 | |||
39 | /** |
||
40 | * Constructor |
||
41 | * |
||
42 | * @param AspectLoader $loader Instance of aspect loader |
||
43 | * @param bool $isInterceptFunctions Optional flag to enable function interception |
||
44 | */ |
||
45 | 4 | public function __construct(AspectLoader $loader, $isInterceptFunctions = false) |
|
51 | |||
52 | /** |
||
53 | * Returns list of function advices for namespace |
||
54 | * |
||
55 | * @param ReflectionFileNamespace $namespace |
||
56 | * @param array|Aop\Advisor[] $advisors List of advisor to match |
||
57 | * |
||
58 | * @return array |
||
59 | */ |
||
60 | 8 | public function getAdvicesForFunctions(ReflectionFileNamespace $namespace, array $advisors) |
|
85 | |||
86 | /** |
||
87 | * Return list of advices for class |
||
88 | * |
||
89 | * @param ParsedReflectionClass $class Class to advise |
||
90 | * @param array|Aop\Advisor[] $advisors List of advisor to match |
||
91 | * |
||
92 | * @return array|Aop\Advice[] List of advices for class |
||
93 | */ |
||
94 | 3 | public function getAdvicesForClass(ParsedReflectionClass $class, array $advisors) |
|
130 | |||
131 | /** |
||
132 | * Returns list of advices from advisor and point filter |
||
133 | * |
||
134 | * @param ParsedReflectionClass $class Class to inject advices |
||
135 | * @param Aop\PointcutAdvisor $advisor Advisor for class |
||
136 | * @param string $advisorId Identifier of advisor |
||
137 | * @param Aop\PointFilter $filter Filter for points |
||
138 | * |
||
139 | * @return array |
||
140 | */ |
||
141 | 2 | private function getAdvicesFromAdvisor( |
|
142 | ParsedReflectionClass $class, |
||
143 | Aop\PointcutAdvisor $advisor, |
||
144 | $advisorId, |
||
145 | Aop\PointFilter $filter) |
||
146 | { |
||
147 | 2 | $classAdvices = []; |
|
148 | 2 | $filterKind = $filter->getKind(); |
|
149 | |||
150 | // Check class only for class filters |
||
151 | 2 | if ($filterKind & Aop\PointFilter::KIND_CLASS) { |
|
152 | if ($filter->matches($class)) { |
||
153 | // Dynamic initialization |
||
154 | if ($filterKind & Aop\PointFilter::KIND_INIT) { |
||
155 | $classAdvices[AspectContainer::INIT_PREFIX]['root'][$advisorId] = $advisor->getAdvice(); |
||
156 | } |
||
157 | // Static initalization |
||
158 | if ($filterKind & Aop\PointFilter::KIND_STATIC_INIT) { |
||
159 | $classAdvices[AspectContainer::STATIC_INIT_PREFIX]['root'][$advisorId] = $advisor->getAdvice(); |
||
160 | } |
||
161 | } |
||
162 | } |
||
163 | |||
164 | // Check methods in class only for method filters |
||
165 | 2 | if ($filterKind & Aop\PointFilter::KIND_METHOD) { |
|
166 | |||
167 | 1 | $mask = ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED; |
|
168 | 1 | foreach ($class->getMethods($mask) as $method) { |
|
169 | /** @var $method ReflectionMethod| */ |
||
170 | 1 | if ($filter->matches($method, $class)) { |
|
171 | 1 | $prefix = $method->isStatic() ? AspectContainer::STATIC_METHOD_PREFIX : AspectContainer::METHOD_PREFIX; |
|
172 | 1 | $classAdvices[$prefix][$method->name][$advisorId] = $advisor->getAdvice(); |
|
173 | } |
||
174 | } |
||
175 | } |
||
176 | |||
177 | // Check properties in class only for property filters |
||
178 | 2 | if ($filterKind & Aop\PointFilter::KIND_PROPERTY) { |
|
179 | 1 | $mask = ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED; |
|
180 | 1 | foreach ($class->getProperties($mask) as $property) { |
|
181 | /** @var $property ReflectionProperty */ |
||
182 | 1 | if ($filter->matches($property, $class) && !$property->isStatic()) { |
|
183 | 1 | $classAdvices[AspectContainer::PROPERTY_PREFIX][$property->name][$advisorId] = $advisor->getAdvice(); |
|
184 | } |
||
185 | } |
||
186 | } |
||
187 | |||
188 | 2 | return $classAdvices; |
|
189 | } |
||
190 | |||
191 | /** |
||
192 | * Returns list of introduction advices from advisor |
||
193 | * |
||
194 | * @param ParsedReflectionClass $class Class to inject advices |
||
195 | * @param Aop\IntroductionAdvisor $advisor Advisor for class |
||
196 | * @param string $advisorId Identifier of advisor |
||
197 | * |
||
198 | * @return array |
||
199 | */ |
||
200 | private function getIntroductionFromAdvisor( |
||
217 | |||
218 | /** |
||
219 | * Returns list of function advices for specific namespace |
||
220 | * |
||
221 | * @param ReflectionFileNamespace $namespace |
||
222 | * @param Aop\PointcutAdvisor $advisor Advisor for class |
||
223 | * @param string $advisorId Identifier of advisor |
||
224 | * @param Aop\PointFilter $pointcut Filter for points |
||
225 | * |
||
226 | * @return array |
||
227 | */ |
||
228 | private function getFunctionAdvicesFromAdvisor( |
||
250 | } |
||
251 |