1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
/* |
4
|
|
|
* Go! AOP framework |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright 2013, Lisachenko Alexander <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Go\Aop\Pointcut; |
13
|
|
|
|
14
|
|
|
use Go\Aop\Pointcut; |
15
|
|
|
use Go\Aop\PointFilter; |
16
|
|
|
use Go\Aop\Support\OrPointFilter; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Logical "OR" pointcut that combines two simple pointcuts |
20
|
|
|
*/ |
21
|
|
|
class OrPointcut extends AndPointcut |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* "Or" pointcut constructor |
26
|
|
|
*/ |
27
|
2 |
|
public function __construct(Pointcut $first, Pointcut $second) |
28
|
|
|
{ |
29
|
2 |
|
$this->first = $first; |
30
|
2 |
|
$this->second = $second; |
31
|
2 |
|
$this->kind = $first->getKind() | $second->getKind(); |
32
|
|
|
|
33
|
2 |
|
$this->classFilter = new OrPointFilter($first->getClassFilter(), $second->getClassFilter()); |
34
|
2 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Performs matching of point of code |
38
|
|
|
* |
39
|
|
|
* @param mixed $point Specific part of code, can be any Reflection class |
40
|
|
|
* @param null|mixed $context Related context, can be class or namespace |
41
|
|
|
* @param null|string|object $instance Invocation instance or string for static calls |
42
|
|
|
* @param null|array $arguments Dynamic arguments for method |
43
|
|
|
*/ |
44
|
|
|
public function matches($point, $context = null, $instance = null, array $arguments = null): bool |
45
|
|
|
{ |
46
|
|
|
return $this->matchPart($this->first, $point, $context, $instance, $arguments) |
47
|
|
|
|| $this->matchPart($this->second, $point, $context, $instance, $arguments); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @inheritDoc |
52
|
|
|
*/ |
53
|
|
|
protected function matchPart(Pointcut $pointcut, $point, $context = null, $instance = null, array $arguments = null) |
54
|
|
|
{ |
55
|
|
|
$pointcutKind = $pointcut->getKind(); |
56
|
|
|
// We need to recheck filter kind one more time, because of OR syntax |
57
|
|
|
switch (true) { |
58
|
|
|
case ($point instanceof \ReflectionMethod && ($pointcutKind & PointFilter::KIND_METHOD)): |
59
|
|
|
case ($point instanceof \ReflectionProperty && ($pointcutKind & PointFilter::KIND_PROPERTY)): |
60
|
|
|
case ($point instanceof \ReflectionClass && ($pointcutKind & PointFilter::KIND_CLASS)): |
61
|
|
|
return parent::matchPart($pointcut, $point, $context, $instance, $arguments); |
|
|
|
|
62
|
|
|
|
63
|
|
|
default: |
64
|
|
|
return false; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
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.