|
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
|
|
|
* Phing task to dynamically augment a previously declared reference. |
|
22
|
|
|
* |
|
23
|
|
|
* @author Siad Ardroumli <[email protected]> |
|
24
|
|
|
* @package phing.tasks.system |
|
25
|
|
|
*/ |
|
26
|
|
|
class AugmentReference extends Task implements TypeAdapter |
|
27
|
|
|
{ |
|
28
|
|
|
private $id; |
|
29
|
|
|
|
|
30
|
2 |
|
public function main() |
|
31
|
|
|
{ |
|
32
|
2 |
|
$this->restoreWrapperId(); |
|
33
|
2 |
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Needed if two different targets reuse the same instance. |
|
37
|
|
|
*/ |
|
38
|
2 |
|
private function restoreWrapperId(): void |
|
39
|
|
|
{ |
|
40
|
2 |
|
if ($this->id !== null) { |
|
41
|
2 |
|
$this->log('restoring augment wrapper ' . $this->id, Project::MSG_DEBUG); |
|
42
|
2 |
|
$wrapper = $this->getWrapper(); |
|
43
|
2 |
|
$wrapper->setAttribute('id', $this->id); |
|
44
|
2 |
|
$wrapper->setElementTag($this->getTaskName()); |
|
45
|
2 |
|
$this->id = null; |
|
46
|
|
|
} |
|
47
|
2 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function setProxy($o) |
|
50
|
|
|
{ |
|
51
|
|
|
throw new LogicException(__METHOD__ . ' unsupported.'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
6 |
|
public function getProxy() |
|
55
|
|
|
{ |
|
56
|
6 |
|
if ($this->getProject() === null) { |
|
57
|
|
|
throw new LogicException($this->getTaskName() . 'Project owner unset'); |
|
58
|
|
|
} |
|
59
|
6 |
|
$this->hijackId(); |
|
60
|
5 |
|
$ref = $this->getProject()->getReference($this->id); |
|
61
|
5 |
|
if ($this->getProject()->hasReference($this->id) && !$ref instanceof UnknownElement) { |
|
62
|
4 |
|
$result = $this->getProject()->getReference($this->id); |
|
63
|
4 |
|
$this->log('project reference ' . $this->id . '=' . get_class($result), Project::MSG_DEBUG); |
|
64
|
4 |
|
return $result; |
|
65
|
|
|
} |
|
66
|
1 |
|
throw new BuildException('Unknown reference "' . $this->id . '"'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
6 |
|
private function hijackId(): void |
|
70
|
|
|
{ |
|
71
|
6 |
|
if ($this->id === null) { |
|
72
|
6 |
|
$wrapper = $this->getWrapper(); |
|
73
|
6 |
|
$this->id = $wrapper->getId(); |
|
74
|
6 |
|
if ($this->id === null) { |
|
75
|
1 |
|
throw new BuildException($this->getTaskName() . " attribute 'id' unset"); |
|
76
|
|
|
} |
|
77
|
5 |
|
$wrapper->setAttribute('id', null); |
|
78
|
5 |
|
$wrapper->removeAttribute('id'); |
|
79
|
5 |
|
$wrapper->setElementTag('augmented reference "' . $this->id . '"'); |
|
80
|
|
|
} |
|
81
|
5 |
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|