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
|
|
/**
|
21
|
|
* Wrapper class that holds the attributes of a Task (or elements
|
22
|
|
* nested below that level) and takes care of configuring that element
|
23
|
|
* at runtime.
|
24
|
|
*
|
25
|
|
* <strong>SMART-UP INLINE DOCS</strong>
|
26
|
|
*
|
27
|
|
* @author Andreas Aderhold <andi@binarycloud.com>
|
28
|
|
* @author Hans Lellelid <hans@xmpl.org>
|
29
|
|
* @package phing
|
30
|
|
*/
|
31
|
|
class RuntimeConfigurable
|
32
|
|
{
|
33
|
|
private $elementTag = null;
|
34
|
|
|
35
|
|
/**
|
36
|
|
* @var array $children
|
37
|
|
*/
|
38
|
|
private $children = [];
|
39
|
|
|
40
|
|
/**
|
41
|
|
* @var object|Task $wrappedObject
|
42
|
|
*/
|
43
|
|
private $wrappedObject = null;
|
44
|
|
|
45
|
|
/**
|
46
|
|
* @var array $attributes
|
47
|
|
*/
|
48
|
|
private $attributes = [];
|
49
|
|
|
50
|
|
/**
|
51
|
|
* @var string $characters
|
52
|
|
*/
|
53
|
|
private $characters = "";
|
54
|
|
|
55
|
|
/**
|
56
|
|
* @var bool $proxyConfigured
|
57
|
|
*/
|
58
|
|
private $proxyConfigured = false;
|
59
|
|
|
60
|
|
/**
|
61
|
|
* @param Task|object $proxy
|
62
|
|
* @param mixed $elementTag The element to wrap.
|
63
|
|
*/
|
64
|
1
|
public function __construct($proxy, $elementTag)
|
65
|
|
{
|
66
|
1
|
$this->wrappedObject = $proxy;
|
67
|
1
|
$this->elementTag = $elementTag;
|
68
|
|
|
69
|
1
|
if ($proxy instanceof Task) {
|
70
|
1
|
$proxy->setRuntimeConfigurableWrapper($this);
|
71
|
|
}
|
72
|
|
}
|
73
|
|
|
74
|
|
/**
|
75
|
|
* @return object|Task
|
76
|
|
*/
|
77
|
1
|
public function getProxy()
|
78
|
|
{
|
79
|
1
|
return $this->wrappedObject;
|
80
|
|
}
|
81
|
|
|
82
|
|
/**
|
83
|
|
* @param object|Task $proxy
|
84
|
|
*
|
85
|
|
* @return void
|
86
|
|
*/
|
87
|
1
|
public function setProxy($proxy)
|
88
|
|
{
|
89
|
1
|
$this->wrappedObject = $proxy;
|
90
|
1
|
$this->proxyConfigured = false;
|
91
|
|
}
|
92
|
|
|
93
|
|
/**
|
94
|
|
* Set's the attributes for the wrapped element.
|
95
|
|
*
|
96
|
|
* @param array $attributes
|
97
|
|
*
|
98
|
|
* @return void
|
99
|
|
*/
|
100
|
1
|
public function setAttributes($attributes)
|
101
|
|
{
|
102
|
1
|
$this->attributes = $attributes;
|
103
|
|
}
|
104
|
|
|
105
|
|
/**
|
106
|
|
* Returns the AttributeList of the wrapped element.
|
107
|
|
*
|
108
|
|
* @return array
|
109
|
|
*/
|
110
|
0
|
public function getAttributes()
|
111
|
|
{
|
112
|
0
|
return $this->attributes;
|
113
|
|
}
|
114
|
|
|
115
|
|
/**
|
116
|
|
* Adds child elements to the wrapped element.
|
117
|
|
*
|
118
|
|
* @param RuntimeConfigurable $child
|
119
|
|
*
|
120
|
|
* @return void
|
121
|
|
*/
|
122
|
1
|
public function addChild(RuntimeConfigurable $child)
|
123
|
|
{
|
124
|
1
|
$this->children[] = $child;
|
125
|
|
}
|
126
|
|
|
127
|
|
/**
|
128
|
|
* Returns the child with index
|
129
|
|
*
|
130
|
|
* @param int $index
|
131
|
|
*
|
132
|
|
* @return RuntimeConfigurable
|
133
|
|
*/
|
134
|
1
|
public function getChild($index)
|
135
|
|
{
|
136
|
1
|
return $this->children[(int) $index];
|
137
|
|
}
|
138
|
|
|
139
|
0
|
public function getChildren()
|
140
|
|
{
|
141
|
0
|
return $this->children;
|
142
|
|
}
|
143
|
|
|
144
|
|
/**
|
145
|
|
* Add characters from #PCDATA areas to the wrapped element.
|
146
|
|
*
|
147
|
|
* @param string $data
|
148
|
|
*
|
149
|
|
* @return void
|
150
|
|
*/
|
151
|
1
|
public function addText($data)
|
152
|
|
{
|
153
|
1
|
$this->characters .= (string) $data;
|
154
|
|
}
|
155
|
|
|
156
|
|
/**
|
157
|
|
* Get the text content of this element. Various text chunks are
|
158
|
|
* concatenated, there is no way (currently) of keeping track of
|
159
|
|
* multiple fragments.
|
160
|
|
*
|
161
|
|
* @return string the text content of this element.
|
162
|
|
*/
|
163
|
1
|
public function getText()
|
164
|
|
{
|
165
|
1
|
return (string) $this->characters;
|
166
|
|
}
|
167
|
|
|
168
|
0
|
public function getElementTag()
|
169
|
|
{
|
170
|
0
|
return $this->elementTag;
|
171
|
|
}
|
172
|
|
|
173
|
|
/**
|
174
|
|
* Reconfigure the element, even if it has already been configured.
|
175
|
|
*
|
176
|
|
* @param Project $p the project instance for this configuration.
|
177
|
|
*/
|
178
|
0
|
public function reconfigure(Project $p)
|
179
|
|
{
|
180
|
0
|
$this->proxyConfigured = false;
|
181
|
0
|
$this->maybeConfigure($p);
|
182
|
|
}
|
183
|
|
|
184
|
|
/**
|
185
|
|
* Configure the wrapped element and all children.
|
186
|
|
*
|
187
|
|
* @param Project $project
|
188
|
|
*
|
189
|
|
* @return void
|
190
|
|
*
|
191
|
|
* @throws BuildException
|
192
|
|
* @throws Exception
|
193
|
|
*/
|
194
|
1
|
public function maybeConfigure(Project $project)
|
195
|
|
{
|
196
|
1
|
if ($this->proxyConfigured) {
|
197
|
1
|
return;
|
198
|
|
}
|
199
|
|
|
200
|
1
|
$id = null;
|
201
|
|
|
202
|
1
|
if ($this->attributes || (isset($this->characters) && $this->characters !== '')) {
|
203
|
1
|
ProjectConfigurator::configure($this->wrappedObject, $this->attributes, $project);
|
204
|
|
|
205
|
1
|
if (isset($this->attributes["id"])) {
|
206
|
1
|
$id = $this->attributes["id"];
|
207
|
|
}
|
208
|
|
|
209
|
1
|
if ($this->characters !== '') {
|
210
|
1
|
ProjectConfigurator::addText($project, $this->wrappedObject, $this->characters);
|
211
|
|
}
|
212
|
1
|
if ($id !== null) {
|
213
|
1
|
$project->addReference($id, $this->wrappedObject);
|
214
|
|
}
|
215
|
|
}
|
216
|
|
|
217
|
1
|
$this->proxyConfigured = true;
|
218
|
|
}
|
219
|
|
|
220
|
1
|
public function setAttribute(string $name, $value)
|
221
|
|
{
|
222
|
1
|
$this->attributes[$name] = $value;
|
223
|
|
}
|
224
|
|
|
225
|
1
|
public function removeAttribute(string $name)
|
226
|
|
{
|
227
|
1
|
unset($this->attributes[$name]);
|
228
|
|
}
|
229
|
|
|
230
|
1
|
public function setElementTag(string $name)
|
231
|
|
{
|
232
|
1
|
$this->elementTag = $name;
|
233
|
|
}
|
234
|
|
|
235
|
1
|
public function getId()
|
236
|
|
{
|
237
|
1
|
return $this->attributes['id'] ?? null;
|
238
|
|
}
|
239
|
|
}
|