1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
/* |
4
|
|
|
* Go! AOP framework |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright 2012, 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\Support; |
13
|
|
|
|
14
|
|
|
use Go\Aop\Advice; |
15
|
|
|
use Go\Aop\Framework\DynamicInvocationMatcherInterceptor; |
16
|
|
|
use Go\Aop\Intercept\Interceptor; |
17
|
|
|
use Go\Aop\Pointcut; |
18
|
|
|
use Go\Aop\PointcutAdvisor; |
19
|
|
|
use Go\Aop\PointFilter; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Convenient Pointcut-driven Advisor implementation. |
23
|
|
|
* |
24
|
|
|
* This is the most commonly used Advisor implementation. It can be used with any pointcut and advice type, |
25
|
|
|
* except for introductions. There is normally no need to subclass this class, or to implement custom Advisors. |
26
|
|
|
*/ |
27
|
|
|
class DefaultPointcutAdvisor extends AbstractGenericAdvisor implements PointcutAdvisor |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Pointcut instance |
32
|
|
|
* |
33
|
|
|
* @var Pointcut |
34
|
|
|
*/ |
35
|
|
|
private $pointcut; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Create a DefaultPointcutAdvisor, specifying Pointcut and Advice. |
39
|
|
|
* |
40
|
|
|
* @param Pointcut $pointcut The Pointcut targeting the Advice |
41
|
|
|
* @param Advice $advice The Advice to run when Pointcut matches |
42
|
|
|
*/ |
43
|
2 |
|
public function __construct(Pointcut $pointcut, Advice $advice) |
44
|
|
|
{ |
45
|
2 |
|
$this->pointcut = $pointcut; |
46
|
2 |
|
parent::__construct($advice); |
47
|
2 |
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
2 |
|
public function getAdvice(): Advice |
53
|
|
|
{ |
54
|
2 |
|
$advice = parent::getAdvice(); |
55
|
2 |
|
if (($advice instanceof Interceptor) && ($this->pointcut->getKind() & PointFilter::KIND_DYNAMIC)) { |
56
|
|
|
$advice = new DynamicInvocationMatcherInterceptor( |
57
|
|
|
$this->pointcut, |
58
|
|
|
$advice |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
2 |
|
return $advice; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get the Pointcut that drives this advisor. |
67
|
|
|
*/ |
68
|
2 |
|
public function getPointcut(): Pointcut |
69
|
|
|
{ |
70
|
2 |
|
return $this->pointcut; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|