CallPointcut::matches()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * \AppserverIo\Doppelgaenger\Entities\Pointcut\CallPointcut
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\Entities\Definitions\FunctionDefinition;
24
25
/**
26
 * Pointcut for specifying functions into which a certain advice has to be weaved.
27
 * Can only be used with a qualified method signature e.g. \AppserverIo\Doppelgaenger\Logger->log()
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({"POINTCUT"})
36
 */
37
class CallPointcut 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 = false;
47
48
    /**
49
     * The type of this pointcut
50
     *
51
     * @var string TYPE
52
     */
53
    const TYPE = 'call';
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
        return '';
88
    }
89
90
    /**
91
     * Whether or not the pointcut matches a given candidate.
92
     * Weave pointcuts will always return true, as they do not pose any condition
93
     *
94
     * @param mixed $candidate Candidate to match against the pointcuts match pattern (getMatchPattern())
95
     *
96
     * @return boolean
97
     */
98
    public function matches($candidate)
99
    {
100
        // if we do not get a function definition we can already assume there is no match
101
        if (!$candidate instanceof FunctionDefinition) {
102
            return false;
103
        }
104
105
        // build up the signature of the candidate function definition and look for a match
106
        $candidateSignature = $candidate->getStructureName() . $this->callType . $candidate->getName();
107
        return fnmatch(str_replace('\\', '\\\\', ltrim($this->getExpression(), '\\')), $candidateSignature);
108
    }
109
}
110