1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* \AppserverIo\Doppelgaenger\Entities\Pointcut\AdvisePointcut |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Bernhard Wick <[email protected]> |
15
|
|
|
* @copyright 2015 TechDivision GmbH - <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/appserver-io/doppelgaenger |
18
|
|
|
* @link http://www.appserver.io/ |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace AppserverIo\Doppelgaenger\Entities\Pointcuts; |
22
|
|
|
|
23
|
|
|
use AppserverIo\Doppelgaenger\Dictionaries\ReservedKeywords; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Pointcut for direct weaving of advice logic. |
27
|
|
|
* Can only be used with a qualified method signature e.g. \AppserverIo\Doppelgaenger\Logger->log(__METHOD__) |
28
|
|
|
* |
29
|
|
|
* @author Bernhard Wick <[email protected]> |
30
|
|
|
* @copyright 2015 TechDivision GmbH - <[email protected]> |
31
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
32
|
|
|
* @link https://github.com/appserver-io/doppelgaenger |
33
|
|
|
* @link http://www.appserver.io/ |
34
|
|
|
* |
35
|
|
|
* @Target({"METHOD","PROPERTY"}) |
36
|
|
|
*/ |
37
|
|
|
class AdvisePointcut extends AbstractSignaturePointcut |
38
|
|
|
{ |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Whether or not the pointcut is considered static, meaning is has to be weaved and evaluated during runtime |
42
|
|
|
* anyway |
43
|
|
|
* |
44
|
|
|
* @var boolean IS_STATIC |
45
|
|
|
*/ |
46
|
|
|
const IS_STATIC = true; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* The type of this pointcut |
50
|
|
|
* |
51
|
|
|
* @var string TYPE |
52
|
|
|
*/ |
53
|
|
|
const TYPE = 'advise'; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Default constructor |
57
|
|
|
* |
58
|
|
|
* @param string $expression String representing the expression defining this pointcut |
59
|
|
|
* @param boolean $isNegated If any match made against this pointcut's expression has to be negated in its result |
60
|
|
|
*/ |
61
|
|
|
public function __construct($expression, $isNegated = false) |
62
|
|
|
{ |
63
|
|
|
// clean any trailing brackets and proceed to parent constructor |
64
|
|
|
parent::__construct(rtrim($expression, '()'), $isNegated); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Returns a string representing a boolean condition which can be used to determine if |
69
|
|
|
* the pointcut has to be executed |
70
|
|
|
* |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
|
|
public function getConditionString() |
74
|
|
|
{ |
75
|
|
|
return 'true'; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Returns a string representing the actual execution of the pointcut logic |
80
|
|
|
* |
81
|
|
|
* @param string|null $assignTo Should the result be assigned and stored for later use? If so, to what? |
82
|
|
|
* |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
public function getExecutionString($assignTo = null) |
86
|
|
|
{ |
87
|
|
|
$assignmentPrefix = ''; |
88
|
|
|
if (!is_null($assignTo)) { |
89
|
|
|
$assignmentPrefix = $assignTo . ' = '; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
// we have to test whether or not we need an instance of the used class first. |
93
|
|
|
// if the call is not static then we do |
94
|
|
|
$string = ''; |
95
|
|
|
$expression = $this->getExpression(); |
96
|
|
|
$invocationCode = '(' . ReservedKeywords::METHOD_INVOCATION_OBJECT . ')'; |
97
|
|
|
if ($this->callType === self::CALL_TYPE_OBJECT) { |
98
|
|
|
// don't forget to create an instance first |
99
|
|
|
$variable = '$' . lcfirst(str_replace('\\', '', $this->structure)); |
100
|
|
|
$string .= $variable . ' = new ' . str_replace('\\\\', '\\', $this->structure) . '(); |
101
|
|
|
'; |
102
|
|
|
$string .= $assignmentPrefix . $variable . $this->callType . $this->function . $invocationCode . '; |
103
|
|
|
'; |
104
|
|
|
|
|
|
|
|
105
|
|
|
} else { |
106
|
|
|
$string .= $assignmentPrefix . $expression . $invocationCode . '; |
107
|
|
|
'; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
return $string; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Whether or not the pointcut matches a given candidate. |
115
|
|
|
* Will always return true, as we do not support regex here right now |
116
|
|
|
* |
117
|
|
|
* @param mixed $candidate Candidate to match against the pointcuts match pattern (getMatchPattern()) |
118
|
|
|
* |
119
|
|
|
* @return boolean |
120
|
|
|
*/ |
121
|
|
|
public function matches($candidate) |
122
|
|
|
{ |
123
|
|
|
return true; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|