|
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\Support\AndPointFilter; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Signature method pointcut checks method signature (modifiers and name) to match it |
|
18
|
|
|
*/ |
|
19
|
|
|
class AndPointcut implements Pointcut |
|
20
|
|
|
{ |
|
21
|
|
|
|
|
22
|
|
|
use PointcutClassFilterTrait; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var Pointcut |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $first; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var Pointcut |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $second; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Returns pointcut kind |
|
36
|
|
|
* |
|
37
|
|
|
* @var int |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $kind = 0; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Signature method matcher constructor |
|
43
|
|
|
* |
|
44
|
|
|
* @param Pointcut $first First filter |
|
45
|
|
|
* @param Pointcut $second Second filter |
|
46
|
|
|
*/ |
|
47
|
3 |
|
public function __construct(Pointcut $first, Pointcut $second) |
|
48
|
|
|
{ |
|
49
|
3 |
|
$this->first = $first; |
|
50
|
3 |
|
$this->second = $second; |
|
51
|
3 |
|
$this->kind = $first->getKind() & $second->getKind(); |
|
52
|
|
|
|
|
53
|
3 |
|
$this->classFilter = new AndPointFilter($first->getClassFilter(), $second->getClassFilter()); |
|
54
|
3 |
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Performs matching of point of code |
|
58
|
|
|
* |
|
59
|
|
|
* @param mixed $point Specific part of code, can be any Reflection class |
|
60
|
|
|
* @param null|mixed $context Related context, can be class or namespace |
|
61
|
|
|
* @param null|string|object $instance Invocation instance or string for static calls |
|
62
|
|
|
* @param null|array $arguments Dynamic arguments for method |
|
63
|
|
|
* |
|
64
|
|
|
* @return bool |
|
65
|
|
|
*/ |
|
66
|
|
|
public function matches($point, $context = null, $instance = null, array $arguments = null) |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->matchPart($this->first, $point, $context, $instance, $arguments) |
|
69
|
|
|
&& $this->matchPart($this->second, $point, $context, $instance, $arguments); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Returns the kind of point filter |
|
74
|
|
|
* |
|
75
|
|
|
* @return integer |
|
76
|
|
|
*/ |
|
77
|
1 |
|
public function getKind() |
|
78
|
|
|
{ |
|
79
|
1 |
|
return $this->kind; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Checks if point filter matches the point |
|
84
|
|
|
* |
|
85
|
|
|
* @param Pointcut $pointcut Pointcut part |
|
86
|
|
|
* @param \ReflectionMethod|\ReflectionProperty $point |
|
87
|
|
|
* @param mixed $context Related context, can be class or namespace |
|
88
|
|
|
* @param object|string|null $instance [Optional] Instance for dynamic matching |
|
89
|
|
|
* @param array $arguments [Optional] Extra arguments for dynamic matching |
|
90
|
|
|
* |
|
91
|
|
|
* @return bool |
|
92
|
|
|
*/ |
|
93
|
|
|
protected function matchPart(Pointcut $pointcut, $point, $context = null, $instance = null, array $arguments = null) |
|
94
|
|
|
{ |
|
95
|
|
|
return $pointcut->matches($point, $context, $instance, $arguments) |
|
96
|
|
|
&& $pointcut->getClassFilter()->matches($context); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|