1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Go! AOP framework |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright 2011, 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\Framework; |
12
|
|
|
|
13
|
|
|
use Closure; |
14
|
|
|
use Serializable; |
15
|
|
|
use Go\Aop\Intercept\Interceptor; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Base interceptor realization |
19
|
|
|
*/ |
20
|
|
|
abstract class BaseInterceptor extends BaseAdvice implements Interceptor, Serializable |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Pointcut expression |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $pointcutExpression = ''; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Advice to call |
31
|
|
|
* |
32
|
|
|
* @var Closure |
33
|
|
|
*/ |
34
|
|
|
protected $adviceMethod; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Default constructor for interceptor |
38
|
|
|
* |
39
|
|
|
* @param Closure $adviceMethod Interceptor advice to call |
40
|
|
|
* @param integer $order Order of interceptor |
41
|
|
|
* @param string $pointcutExpression Pointcut expression or advice name |
42
|
|
|
*/ |
43
|
|
|
public function __construct(Closure $adviceMethod, $order = 0, $pointcutExpression = '') |
44
|
|
|
{ |
45
|
|
|
$this->adviceMethod = $adviceMethod; |
46
|
|
|
$this->order = $order; |
47
|
|
|
$this->pointcutExpression = $pointcutExpression; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Getter for extracting the advice closure from Interceptor |
52
|
|
|
* |
53
|
|
|
* @return callable|null |
54
|
|
|
*/ |
55
|
|
|
public function getRawAdvice() |
56
|
|
|
{ |
57
|
|
|
return $this->adviceMethod; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Serializes an interceptor into string representation |
62
|
|
|
* |
63
|
|
|
* @return string the string representation of the object or null |
64
|
|
|
*/ |
65
|
|
|
public function serialize() |
66
|
|
|
{ |
67
|
|
|
$vars = array_filter(get_object_vars($this)); |
68
|
|
|
$vars['adviceMethod'] = static::serializeAdvice($this->adviceMethod); |
69
|
|
|
|
70
|
|
|
return serialize($vars); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Unserialize an interceptor from the string |
75
|
|
|
* |
76
|
|
|
* @param string $serialized The string representation of the object. |
77
|
|
|
* @return void |
78
|
|
|
*/ |
79
|
|
|
public function unserialize($serialized) |
80
|
|
|
{ |
81
|
|
|
$vars = unserialize($serialized); |
82
|
|
|
$vars['adviceMethod'] = static::unserializeAdvice($vars['adviceMethod']); |
83
|
|
|
foreach ($vars as $key=>$value) { |
|
|
|
|
84
|
|
|
$this->$key = $value; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|