|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
/* |
|
5
|
|
|
* Go! AOP framework |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright Copyright 2012, Lisachenko Alexander <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* This source file is subject to the license that is bundled |
|
10
|
|
|
* with this source code in the file LICENSE. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Go\Aop\Pointcut; |
|
14
|
|
|
|
|
15
|
|
|
use Go\Aop\Pointcut; |
|
16
|
|
|
use Go\Aop\PointFilter; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Signature pointcut checks element signature (modifiers and name) to match it |
|
20
|
|
|
*/ |
|
21
|
|
|
class SignaturePointcut implements Pointcut |
|
22
|
|
|
{ |
|
23
|
|
|
use PointcutClassFilterTrait; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Element name to match, can contain wildcards **,*,?,| |
|
27
|
|
|
*/ |
|
28
|
|
|
protected string $name = ''; |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Regular expression for pattern matching |
|
32
|
|
|
*/ |
|
33
|
|
|
protected string $regexp; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Modifier filter for element |
|
37
|
|
|
*/ |
|
38
|
|
|
protected PointFilter $modifierFilter; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Filter kind, e.g. self::KIND_CLASS |
|
42
|
|
|
*/ |
|
43
|
|
|
protected int $filterKind = 0; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Signature matcher constructor |
|
47
|
26 |
|
*/ |
|
48
|
|
|
public function __construct(int $filterKind, string $name, PointFilter $modifierFilter) |
|
49
|
26 |
|
{ |
|
50
|
26 |
|
$this->filterKind = $filterKind; |
|
51
|
26 |
|
$this->name = $name; |
|
52
|
26 |
|
$this->regexp = strtr( |
|
53
|
|
|
preg_quote($this->name, '/'), |
|
54
|
|
|
[ |
|
55
|
|
|
'\\*' => '[^\\\\]+?', |
|
56
|
|
|
'\\*\\*' => '.+?', |
|
57
|
26 |
|
'\\?' => '.', |
|
58
|
26 |
|
'\\|' => '|' |
|
59
|
|
|
] |
|
60
|
|
|
); |
|
61
|
|
|
$this->modifierFilter = $modifierFilter; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Performs matching of point of code |
|
66
|
|
|
* |
|
67
|
|
|
* @param mixed $point Specific part of code, can be any Reflection class |
|
68
|
7 |
|
* @param null|mixed $context Related context, can be class or namespace |
|
69
|
|
|
* @param null|string|object $instance Invocation instance or string for static calls |
|
70
|
7 |
|
* @param null|array $arguments Dynamic arguments for method |
|
71
|
1 |
|
*/ |
|
72
|
|
|
public function matches($point, $context = null, $instance = null, array $arguments = null): bool |
|
73
|
|
|
{ |
|
74
|
6 |
|
if (!$this->modifierFilter->matches($point, $context)) { |
|
75
|
|
|
return false; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return ($point->name === $this->name) || (bool)preg_match("/^(?:{$this->regexp})$/", $point->name); |
|
79
|
|
|
} |
|
80
|
6 |
|
|
|
81
|
|
|
/** |
|
82
|
6 |
|
* Returns the kind of point filter |
|
83
|
|
|
*/ |
|
84
|
|
|
public function getKind(): int |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->filterKind; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|