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\Pointcut; |
12
|
|
|
|
13
|
|
|
use ReflectionFunction; |
14
|
|
|
use Go\Aop\Pointcut; |
15
|
|
|
use Go\Aop\PointFilter; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Signature method pointcut checks method signature (modifiers and name) to match it |
19
|
|
|
*/ |
20
|
|
|
class FunctionPointcut implements Pointcut |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var PointFilter |
24
|
|
|
*/ |
25
|
|
|
protected $nsFilter; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Function name to match, can contain wildcards *,? |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
protected $functionName = ''; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Regular expression for matching |
36
|
|
|
* |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected $regexp; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Function matcher constructor |
43
|
|
|
* |
44
|
|
|
* @param string $functionName Name of the function to match or glob pattern |
45
|
|
|
*/ |
46
|
|
|
public function __construct($functionName) |
47
|
3 |
|
{ |
48
|
|
|
$this->functionName = $functionName; |
49
|
3 |
|
$this->regexp = strtr(preg_quote($this->functionName, '/'), array( |
50
|
3 |
|
'\\*' => '.*?', |
51
|
3 |
|
'\\?' => '.' |
52
|
|
|
)); |
53
|
|
|
} |
54
|
3 |
|
|
55
|
|
|
/** |
56
|
|
|
* Performs matching of point of code |
57
|
|
|
* |
58
|
|
|
* @param mixed $function Specific part of code, can be any Reflection class |
59
|
|
|
* @param mixed $context Related context, can be class or namespace |
60
|
|
|
* @param null|string|object $instance Invocation instance or string for static calls |
61
|
|
|
* @param null|array $arguments Dynamic arguments for method |
62
|
|
|
* |
63
|
|
|
* @return bool |
64
|
|
|
*/ |
65
|
|
|
public function matches($function, $context = null, $instance = null, array $arguments = null) |
66
|
|
|
{ |
67
|
|
|
if (!$function instanceof ReflectionFunction) { |
68
|
|
|
return false; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return ($function->name === $this->functionName) || (bool) preg_match("/^{$this->regexp}$/", $function->name); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Returns the kind of point filter |
76
|
|
|
* |
77
|
|
|
* @return integer |
78
|
|
|
*/ |
79
|
|
|
public function getKind() |
80
|
|
|
{ |
81
|
|
|
return self::KIND_FUNCTION; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Return the class filter for this pointcut. |
86
|
|
|
* |
87
|
|
|
* @return PointFilter |
88
|
|
|
*/ |
89
|
|
|
public function getClassFilter() |
90
|
|
|
{ |
91
|
|
|
return $this->nsFilter; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function setNamespaceFilter($nsFilter) |
95
|
|
|
{ |
96
|
3 |
|
$this->nsFilter = $nsFilter; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|