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 <siad.ardroumli@gmail.com>
24
 * @package phing.tasks.system
25
 */
26
class AugmentReference extends Task implements TypeAdapter
27
{
28
    private $id;
29

30 1
    public function main()
31
    {
32 1
        $this->restoreWrapperId();
33
    }
34

35
    /**
36
     * Needed if two different targets reuse the same instance.
37
     */
38 1
    private function restoreWrapperId(): void
39
    {
40 1
        if ($this->id !== null) {
41 1
            $this->log('restoring augment wrapper ' . $this->id, Project::MSG_DEBUG);
42 1
            $wrapper = $this->getWrapper();
43 1
            $wrapper->setAttribute('id', $this->id);
44 1
            $wrapper->setElementTag($this->getTaskName());
45 1
            $this->id = null;
46
        }
47
    }
48

49 0
    public function setProxy($o)
50
    {
51 0
        throw new LogicException(__METHOD__ . ' unsupported.');
52
    }
53

54 1
    public function getProxy()
55
    {
56 1
        if ($this->getProject() === null) {
57 0
            throw new LogicException($this->getTaskName() . 'Project owner unset');
58
        }
59 1
        $this->hijackId();
60 1
        $ref = $this->getProject()->getReference($this->id);
61 1
        if ($this->getProject()->hasReference($this->id) && !$ref instanceof UnknownElement) {
62 1
            $result = $this->getProject()->getReference($this->id);
63 1
            $this->log('project reference ' . $this->id . '=' . get_class($result), Project::MSG_DEBUG);
64 1
            return $result;
65
        }
66 1
        throw new BuildException('Unknown reference "' . $this->id . '"');
67
    }
68

69 1
    private function hijackId(): void
70
    {
71 1
        if ($this->id === null) {
72 1
            $wrapper = $this->getWrapper();
73 1
            $this->id = $wrapper->getId();
74 1
            if ($this->id === null) {
75 1
                throw new BuildException($this->getTaskName() . " attribute 'id' unset");
76
            }
77 1
            $wrapper->setAttribute('id', null);
78 1
            $wrapper->removeAttribute('id');
79 1
            $wrapper->setElementTag('augmented reference "' . $this->id . '"');
80
        }
81
    }
82
}

Read our documentation on viewing source code .

Loading