1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the LGPL. For more information please see |
17
|
|
|
* <http://phing.info>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
require_once 'phing/tasks/system/condition/ConditionBase.php'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* <condition> task as a generalization of <available> |
24
|
|
|
* |
25
|
|
|
* <p>This task supports boolean logic as well as pluggable conditions |
26
|
|
|
* to decide, whether a property should be set.</p> |
27
|
|
|
* |
28
|
|
|
* <p>This task does not extend Task to take advantage of |
29
|
|
|
* ConditionBase.</p> |
30
|
|
|
* |
31
|
|
|
* @author Andreas Aderhold <[email protected]> |
32
|
|
|
* @copyright 2001,2002 THYRELL. All rights reserved |
33
|
|
|
* @package phing.tasks.system |
34
|
|
|
*/ |
35
|
|
|
class ConditionTask extends ConditionBase |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* @var string $property |
39
|
|
|
*/ |
40
|
|
|
private $property; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string $value |
44
|
|
|
*/ |
45
|
|
|
private $value = "true"; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var string $alternative |
49
|
|
|
*/ |
50
|
|
|
private $alternative; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Constructor, names this task "condition". |
54
|
|
|
*/ |
55
|
31 |
|
public function __construct() |
56
|
|
|
{ |
57
|
31 |
|
parent::__construct('condition'); |
58
|
31 |
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* The name of the property to set. Required. |
62
|
|
|
* |
63
|
|
|
* @param string $p |
64
|
|
|
* @return void |
65
|
|
|
*/ |
66
|
31 |
|
public function setProperty($p) |
67
|
|
|
{ |
68
|
31 |
|
$this->property = $p; |
69
|
31 |
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* The value for the property to set. Defaults to "true". |
73
|
|
|
* |
74
|
|
|
* @param string $v |
75
|
|
|
* @return void |
76
|
|
|
*/ |
77
|
|
|
public function setValue($v) |
78
|
|
|
{ |
79
|
|
|
$this->value = $v; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* The value for the property to set, if condition evaluates to false. |
84
|
|
|
* If this attribute is not specified, the property will not be set. |
85
|
|
|
* |
86
|
|
|
* @param string $v |
87
|
|
|
*/ |
88
|
1 |
|
public function setElse($v) |
89
|
|
|
{ |
90
|
1 |
|
$this->alternative = $v; |
91
|
1 |
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* See whether our nested condition holds and set the property. |
95
|
|
|
* |
96
|
|
|
* @throws BuildException |
97
|
|
|
* @return void |
98
|
|
|
*/ |
99
|
31 |
|
public function main() |
100
|
|
|
{ |
101
|
31 |
|
if ($this->countConditions() > 1) { |
102
|
|
|
throw new BuildException( |
103
|
|
|
"You must not nest more than one condition into <condition>" |
104
|
|
|
); |
105
|
|
|
} |
106
|
31 |
|
if ($this->countConditions() < 1) { |
107
|
|
|
throw new BuildException( |
108
|
|
|
"You must nest a condition into <condition>" |
109
|
|
|
); |
110
|
|
|
} |
111
|
31 |
|
if ($this->property === null) { |
112
|
|
|
throw new BuildException('The property attribute is required.'); |
113
|
|
|
} |
114
|
31 |
|
$cs = $this->getIterator(); |
115
|
31 |
|
if ($cs->current()->evaluate()) { |
116
|
16 |
|
$this->log("Condition true; setting " . $this->property . " to " . $this->value, Project::MSG_DEBUG); |
117
|
16 |
|
$this->project->setNewProperty($this->property, $this->value); |
118
|
21 |
|
} elseif ($this->alternative !== null) { |
119
|
1 |
|
$this->log("Condition false; setting " . $this->property . " to " . $this->alternative, Project::MSG_DEBUG); |
120
|
1 |
|
$this->project->setNewProperty($this->property, $this->alternative); |
121
|
|
|
} else { |
122
|
20 |
|
$this->log('Condition false; not setting ' . $this->property, Project::MSG_DEBUG); |
123
|
|
|
} |
124
|
31 |
|
} |
125
|
|
|
} |
126
|
|
|
|