1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* \AppserverIo\Doppelgaenger\Entities\Pointcut\WeavePointcut |
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
|
|
|
/** |
24
|
|
|
* Pointcut for direct weaving of advice logic. |
25
|
|
|
* Can only be used with a qualified method signature e.g. \AppserverIo\Doppelgaenger\Logger->log(__METHOD__) |
26
|
|
|
* |
27
|
|
|
* @author Bernhard Wick <[email protected]> |
28
|
|
|
* @copyright 2015 TechDivision GmbH - <[email protected]> |
29
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
30
|
|
|
* @link https://github.com/appserver-io/doppelgaenger |
31
|
|
|
* @link http://www.appserver.io/ |
32
|
|
|
* |
33
|
|
|
* @Target({"METHOD","PROPERTY"}) |
34
|
|
|
*/ |
35
|
|
|
class WeavePointcut extends AbstractSignaturePointcut |
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Whether or not the pointcut is considered static, meaning is has to be weaved and evaluated during runtime |
40
|
|
|
* anyway |
41
|
|
|
* |
42
|
|
|
* @var boolean IS_STATIC |
43
|
|
|
*/ |
44
|
|
|
const IS_STATIC = true; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* The type of this pointcut |
48
|
|
|
* |
49
|
|
|
* @var string TYPE |
50
|
|
|
*/ |
51
|
|
|
const TYPE = 'weave'; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Returns a string representing a boolean condition which can be used to determine if |
55
|
|
|
* the pointcut has to be executed |
56
|
|
|
* |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
|
|
public function getConditionString() |
60
|
|
|
{ |
61
|
|
|
return 'true'; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Returns a string representing the actual execution of the pointcut logic |
66
|
|
|
* |
67
|
|
|
* @param string|null $assignTo Should the result be assigned and stored for later use? If so, to what? |
68
|
|
|
* |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
public function getExecutionString($assignTo = null) |
72
|
|
|
{ |
73
|
|
|
$assignmentPrefix = ''; |
74
|
|
|
if (!is_null($assignTo)) { |
75
|
|
|
$assignmentPrefix = $assignTo . ' = '; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
// we have to test whether or not we need an instance of the used class first. |
79
|
|
|
// if the call is not static then we do |
80
|
|
|
$string = ''; |
81
|
|
|
$expression = $this->getExpression(); |
82
|
|
|
if ($this->callType === self::CALL_TYPE_OBJECT) { |
83
|
|
|
// don't forget to create an instance first |
84
|
|
|
$variable = '$' . lcfirst(str_replace('\\', '', $this->structure)); |
85
|
|
|
$string .= $variable . ' = new ' . $this->structure . '(); |
86
|
|
|
'; |
87
|
|
|
$string .= $assignmentPrefix . $variable . $this->callType . $this->function . '; |
88
|
|
|
'; |
89
|
|
|
|
|
|
|
|
90
|
|
|
} else { |
91
|
|
|
$string .= $assignmentPrefix . $expression . '; |
92
|
|
|
'; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return $string; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Whether or not the pointcut matches a given candidate. |
100
|
|
|
* Weave pointcuts will always return true, as they do not pose any condition |
101
|
|
|
* |
102
|
|
|
* @param mixed $candidate Candidate to match against the pointcuts match pattern (getMatchPattern()) |
103
|
|
|
* |
104
|
|
|
* @return boolean |
105
|
|
|
*/ |
106
|
|
|
public function matches($candidate) |
107
|
|
|
{ |
108
|
|
|
return true; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|