1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Go! AOP framework |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright 2013, Lisachenko Alexander <[email protected]> |
6
|
|
|
* |
7
|
|
|
* This source file is subject to the license that is bundled |
8
|
|
|
* with this source code in the file LICENSE. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Go\Aop\Pointcut; |
12
|
|
|
|
13
|
|
|
use Go\Aop\Pointcut; |
14
|
|
|
use Go\Aop\PointFilter; |
15
|
|
|
use Go\Aop\Support\OrPointFilter; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Signature method pointcut checks method signature (modifiers and name) to match it |
19
|
|
|
*/ |
20
|
|
|
class OrPointcut extends AndPointcut |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Signature method matcher constructor |
25
|
|
|
* |
26
|
|
|
* @param Pointcut $first First filter |
27
|
|
|
* @param Pointcut $second Second filter |
28
|
|
|
*/ |
29
|
2 |
|
public function __construct(Pointcut $first, Pointcut $second) |
30
|
|
|
{ |
31
|
2 |
|
$this->first = $first; |
32
|
2 |
|
$this->second = $second; |
33
|
2 |
|
$this->kind = $first->getKind() | $second->getKind(); |
34
|
|
|
|
35
|
2 |
|
$this->classFilter = new OrPointFilter($first->getClassFilter(), $second->getClassFilter()); |
36
|
2 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Performs matching of point of code |
40
|
|
|
* |
41
|
|
|
* @param mixed $point Specific part of code, can be any Reflection class |
42
|
|
|
* @param null|mixed $context Related context, can be class or namespace |
43
|
|
|
* @param null|string|object $instance Invocation instance or string for static calls |
44
|
|
|
* @param null|array $arguments Dynamic arguments for method |
45
|
|
|
* |
46
|
|
|
* @return bool |
47
|
|
|
*/ |
48
|
|
|
public function matches($point, $context = null, $instance = null, array $arguments = null) |
49
|
|
|
{ |
50
|
|
|
return $this->matchPart($this->first, $point, $context, $instance, $arguments) |
51
|
|
|
|| $this->matchPart($this->second, $point, $context, $instance, $arguments); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @inheritDoc |
56
|
|
|
*/ |
57
|
|
|
protected function matchPart(Pointcut $pointcut, $point, $context = null, $instance = null, array $arguments = null) |
58
|
|
|
{ |
59
|
|
|
$pointcutKind = $pointcut->getKind(); |
60
|
|
|
// We need to recheck filter kind one more time, because of OR syntax |
61
|
|
|
switch (true) { |
62
|
|
|
case ($point instanceof \ReflectionMethod && ($pointcutKind & PointFilter::KIND_METHOD)): |
63
|
|
|
case ($point instanceof \ReflectionProperty && ($pointcutKind & PointFilter::KIND_PROPERTY)): |
64
|
|
|
case ($point instanceof \ReflectionClass && ($pointcutKind & PointFilter::KIND_CLASS)): |
65
|
|
|
return parent::matchPart($pointcut, $point, $context, $instance, $arguments); |
|
|
|
|
66
|
|
|
|
67
|
|
|
default: |
68
|
|
|
return false; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.