1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* \AppserverIo\Doppelgaenger\Entities\Pointcuts\AndPointcut |
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 to and-connect two other pointcuts logically |
25
|
|
|
* |
26
|
|
|
* @author Bernhard Wick <[email protected]> |
27
|
|
|
* @copyright 2015 TechDivision GmbH - <[email protected]> |
28
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
29
|
|
|
* @link https://github.com/appserver-io/doppelgaenger |
30
|
|
|
* @link http://www.appserver.io/ |
31
|
|
|
* |
32
|
|
|
* @Target({"ADVICE", "METHOD","PROPERTY"}) |
33
|
|
|
*/ |
34
|
|
|
class AndPointcut extends AbstractConnectorPointcut |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* Connector which connects two pointcuts in a logical manner |
38
|
|
|
* |
39
|
|
|
* @var string CONNECTOR |
40
|
|
|
*/ |
41
|
|
|
const CONNECTOR = self::CONNECTOR_AND; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* The type of this pointcut |
45
|
|
|
* |
46
|
|
|
* @var string TYPE |
47
|
|
|
*/ |
48
|
|
|
const TYPE = 'and'; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Returns a string representing a boolean condition which can be used to determine if |
52
|
|
|
* the pointcut has to be executed |
53
|
|
|
* |
54
|
|
|
* @return string |
55
|
|
|
*/ |
56
|
|
|
public function getConditionString() |
57
|
|
|
{ |
58
|
|
|
// we have to check if any of these conditions can be omitted in terms of boolean algebra |
59
|
|
|
if ($this->leftPointcut->getConditionString() === 'true' && $this->rightPointcut->getConditionString() === 'true') { |
60
|
|
|
return 'true'; |
61
|
|
|
|
|
|
|
|
62
|
|
|
} elseif ($this->leftPointcut->getConditionString() === 'true') { |
63
|
|
|
return $this->rightPointcut->getConditionString(); |
64
|
|
|
|
|
|
|
|
65
|
|
|
} elseif ($this->rightPointcut->getConditionString() === 'true') { |
66
|
|
|
return $this->leftPointcut->getConditionString(); |
67
|
|
|
|
|
|
|
|
68
|
|
View Code Duplication |
} else { |
69
|
|
|
return '(' . $this->leftPointcut->getConditionString() . $this->getConnector(). |
70
|
|
|
$this->rightPointcut->getConditionString() . ')'; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Whether or not the pointcut matches a given candidate. |
76
|
|
|
* For connector pointcuts this mostly depends on the connected pointcuts |
77
|
|
|
* |
78
|
|
|
* @param mixed $candidate Candidate to match against the pointcuts match pattern (getMatchPattern()) |
79
|
|
|
* |
80
|
|
|
* @return boolean |
81
|
|
|
*/ |
82
|
|
|
public function matches($candidate) |
83
|
|
|
{ |
84
|
|
|
return ($this->leftPointcut->matches($candidate) && $this->rightPointcut->matches($candidate)); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|