1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Go! AOP framework |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright 2012, 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\Support; |
12
|
|
|
|
13
|
|
|
use Go\Aop\Advice; |
14
|
|
|
use Go\Aop\Framework\DynamicInvocationMatcherInterceptor; |
15
|
|
|
use Go\Aop\Intercept\Interceptor; |
16
|
|
|
use Go\Aop\Pointcut; |
17
|
|
|
use Go\Aop\PointFilter; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Convenient Pointcut-driven Advisor implementation. |
21
|
|
|
* |
22
|
|
|
* This is the most commonly used Advisor implementation. It can be used with any pointcut and advice type, |
23
|
|
|
* except for introductions. There is normally no need to subclass this class, or to implement custom Advisors. |
24
|
|
|
*/ |
25
|
|
|
class DefaultPointcutAdvisor extends AbstractGenericPointcutAdvisor |
26
|
|
|
{ |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Pointcut instance |
30
|
|
|
* |
31
|
|
|
* @var Pointcut |
32
|
|
|
*/ |
33
|
|
|
private $pointcut; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Create a DefaultPointcutAdvisor, specifying Pointcut and Advice. |
37
|
|
|
* |
38
|
|
|
* @param Pointcut $pointcut The Pointcut targeting the Advice |
39
|
|
|
* @param Advice $advice The Advice to run when Pointcut matches |
40
|
|
|
*/ |
41
|
2 |
|
public function __construct(Pointcut $pointcut, Advice $advice) |
42
|
|
|
{ |
43
|
2 |
|
$this->pointcut = $pointcut; |
44
|
2 |
|
parent::__construct($advice); |
45
|
2 |
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
2 |
|
public function getAdvice() |
51
|
|
|
{ |
52
|
2 |
|
$advice = parent::getAdvice(); |
53
|
2 |
|
if (($advice instanceof Interceptor) && ($this->pointcut->getKind() & PointFilter::KIND_DYNAMIC)) { |
54
|
|
|
$advice = new DynamicInvocationMatcherInterceptor( |
55
|
|
|
$this->pointcut, |
56
|
|
|
$advice |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
2 |
|
return $advice; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Get the Pointcut that drives this advisor. |
66
|
|
|
* |
67
|
|
|
* @return Pointcut The pointcut |
68
|
|
|
*/ |
69
|
2 |
|
public function getPointcut() |
70
|
|
|
{ |
71
|
2 |
|
return $this->pointcut; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Specify the pointcut targeting the advice. |
76
|
|
|
* |
77
|
|
|
* @param Pointcut $pointcut The Pointcut targeting the Advice |
78
|
|
|
*/ |
79
|
|
|
public function setPointcut(Pointcut $pointcut) |
80
|
|
|
{ |
81
|
|
|
$this->pointcut = $pointcut; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Return string representation of object |
86
|
|
|
* |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
public function __toString() |
90
|
|
|
{ |
91
|
|
|
$pointcutClass = get_class($this->getPointcut()); |
92
|
|
|
$adviceClass = get_class($this->getAdvice()); |
93
|
|
|
|
94
|
|
|
return static::class . ": pointcut [{$pointcutClass}]; advice [{$adviceClass}]"; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|