summaryrefslogtreecommitdiff
path: root/buildscripts/phing/classes/phing/tasks/system/condition/ConditionBase.php
blob: e21ce4e41f4b1b77d2ad945f03baa2898f39001f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
/*
 *  $Id: 8721880badf6aee475a8cb87c88ca3dc4299efb8 $
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This software consists of voluntary contributions made by many individuals
 * and is licensed under the LGPL. For more information please see
 * <http://phing.info>.
 */

require_once 'phing/ProjectComponent.php';
include_once 'phing/Project.php';
include_once 'phing/tasks/system/AvailableTask.php';
include_once 'phing/tasks/system/condition/Condition.php';

/**
 *  Abstract baseclass for the <condition> task as well as several
 *  conditions - ensures that the types of conditions inside the task
 *  and the "container" conditions are in sync.
 * 
 *  @author  Hans Lellelid <hans@xmpl.org>
 *  @author    Andreas Aderhold <andi@binarycloud.com>
 *  @copyright 2001,2002 THYRELL. All rights reserved
 *  @version   $Id$
 *  @package   phing.tasks.system.condition
 */
abstract class ConditionBase extends ProjectComponent implements IteratorAggregate {
        
    public $conditions = array(); // needs to be public for "inner" class access

    function countConditions() {
        return count($this->conditions);
    }
    
    /**
     * Required for IteratorAggregate
     */
    function getIterator() {
        return new ConditionEnumeration($this);
    }
    
    function getConditions() {
        return $this->conditions;
    }

    /**
     * @return void
     */
    function addAvailable(AvailableTask $a) {
        $this->conditions[] = $a;
    }

    /**
     * @return NotCondition
     */
    function createNot() {
        include_once 'phing/tasks/system/condition/NotCondition.php';
        $num = array_push($this->conditions, new NotCondition());
        return $this->conditions[$num-1];        
    }

    /**
     * @return AndCondition
     */
    function createAnd() {
        include_once 'phing/tasks/system/condition/AndCondition.php';
        $num = array_push($this->conditions, new AndCondition());
        return $this->conditions[$num-1];
    }
    
    /**
     * @return OrCondition
     */
    function createOr() {
        include_once 'phing/tasks/system/condition/OrCondition.php';
        $num = array_push($this->conditions, new OrCondition());
        return $this->conditions[$num-1];        
    }

    /**
     * @return EqualsCondition
     */
    function createEquals() {
        include_once 'phing/tasks/system/condition/EqualsCondition.php';  
        $num = array_push($this->conditions, new EqualsCondition());
        return $this->conditions[$num-1];
    }

    /**
     * @return OsCondition
     */
    function createOs() {
        include_once 'phing/tasks/system/condition/OsCondition.php';
        $num = array_push($this->conditions, new OsCondition());
        return $this->conditions[$num-1];
    }
   
    /**
     * @return IsFalseCondition
     */
    function createIsFalse() {
        include_once 'phing/tasks/system/condition/IsFalseCondition.php';
        $num = array_push($this->conditions, new IsFalseCondition());
        return $this->conditions[$num-1];
    }
   
    /**
     * @return IsTrueCondition
     */
    function createIsTrue() {
        include_once 'phing/tasks/system/condition/IsTrueCondition.php';
        $num = array_push($this->conditions, new IsTrueCondition());
        return $this->conditions[$num-1];
    }
   
    /**
     * @return ContainsCondition
     */
    function createContains() {
        include_once 'phing/tasks/system/condition/ContainsCondition.php';
        $num = array_push($this->conditions, new ContainsCondition());
        return $this->conditions[$num-1];
    }
   
    /**
     * @return IsSetCondition
     */
    function createIsSet() {
        include_once 'phing/tasks/system/condition/IsSetCondition.php';
        $num = array_push($this->conditions, new IsSetCondition());
        return $this->conditions[$num-1];
    }

    /**
     * @return ReferenceExistsCondition
     */
    function createReferenceExists() {
        include_once 'phing/tasks/system/condition/ReferenceExistsCondition.php';
        $num = array_push($this->conditions, new ReferenceExistsCondition());
        return $this->conditions[$num-1];
    }

}

/**
 * "Inner" class for handling enumerations.
 * Uses build-in PHP5 iterator support.
 *
 * @package   phing.tasks.system.condition
 */
class ConditionEnumeration implements Iterator {
    
    /** Current element number */
    private $num = 0;
    
    /** "Outer" ConditionBase class. */
    private $outer;

    function __construct(ConditionBase $outer) {
        $this->outer = $outer;
    }
    
    public function valid() {
        return $this->outer->countConditions() > $this->num;
    }

    function current() {
        $o = $this->outer->conditions[$this->num];
        if ($o instanceof ProjectComponent) {
            $o->setProject($this->outer->getProject());
        }
        return $o;
    }
    
    function next() {
        $this->num++;
    }
    
    function key() {
        return $this->num;
    }
    
    function rewind() {
        $this->num = 0;
    }
}