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
 * Call another target in the same project.
22
 *
23
 * <samp>
24
 *    <target name="foo">
25
 *      <phingcall target="bar">
26
 *        <property name="property1" value="aaaaa" />
27
 *        <property name="foo" value="baz" />
28
 *       </phingcall>
29
 *    </target>
30
 *
31
 *    <target name="bar" depends="init">
32
 *      <echo message="prop is ${property1} ${foo}" />
33
 *    </target>
34
 * </samp>
35
 *
36
 * This only works as expected if neither property1 nor foo are defined in the project itself.
37
 *
38
 * @author    Andreas Aderhold <andi@binarycloud.com>
39
 * @copyright 2001,2002 THYRELL. All rights reserved
40
 * @package   phing.tasks.system
41
 */
42
class PhingCallTask extends Task
43
{
44

45
    /**
46
     * The called Phing task.
47
     *
48
     * @var PhingTask
49
     */
50
    private $callee;
51

52
    /**
53
     * The target to call.
54
     *
55
     * @var string
56
     */
57
    private $subTarget;
58

59
    /**
60
     * Whether to inherit all properties from current project.
61
     *
62
     * @var boolean
63
     */
64
    private $inheritAll = true;
65

66
    /**
67
     * Whether to inherit refs from current project.
68
     *
69
     * @var boolean
70
     */
71
    private $inheritRefs = false;
72

73
    /**
74
     *  If true, pass all properties to the new Phing project.
75
     *  Defaults to true. Future use.
76
     *
77
     * @param boolean new value
78
     */
79 1
    public function setInheritAll($inherit)
80
    {
81 1
        $this->inheritAll = (bool) $inherit;
82
    }
83

84
    /**
85
     *  If true, pass all references to the new Phing project.
86
     *  Defaults to false. Future use.
87
     *
88
     * @param boolean new value
89
     */
90 1
    public function setInheritRefs($inheritRefs)
91
    {
92 1
        $this->inheritRefs = (bool) $inheritRefs;
93
    }
94

95
    /**
96
     * Alias for createProperty
97
     *
98
     * @see createProperty()
99
     */
100 0
    public function createParam()
101
    {
102 0
        if ($this->callee === null) {
103 0
            $this->init();
104
        }
105

106 0
        return $this->callee->createProperty();
107
    }
108

109
    /**
110
     * Property to pass to the invoked target.
111
     */
112 1
    public function createProperty()
113
    {
114 1
        if ($this->callee === null) {
115 0
            $this->init();
116
        }
117

118 1
        return $this->callee->createProperty();
119
    }
120

121
    /**
122
     * Target to execute, required.
123
     *
124
     * @param string $target
125
     */
126 1
    public function setTarget(string $target): void
127
    {
128 1
        if ($this->callee === null) {
129 0
            $this->init();
130
        }
131 1
        $this->callee->setTarget($target);
132 1
        $this->subTarget = $target;
133
    }
134

135
    /**
136
     * Reference element identifying a data type to carry
137
     * over to the invoked target.
138
     *
139
     * @param PhingReference $r the specified `PhingReference`.
140
     */
141 1
    public function addReference(PhingReference $r)
142
    {
143 1
        if ($this->callee === null) {
144 0
            $this->init();
145
        }
146 1
        $this->callee->addReference($r);
147
    }
148

149
    /**
150
     *  init this task by creating new instance of the phing task and
151
     *  configuring it's by calling its own init method.
152
     */
153 1
    public function init()
154
    {
155 1
        $this->callee = new PhingTask($this);
156 1
        $this->callee->setHaltOnFailure(true);
157 1
        $this->callee->init();
158
    }
159

160
    /**
161
     *  hand off the work to the phing task of ours, after setting it up
162
     *
163
     * @throws BuildException on validation failure or if the target didn't
164
     *                        execute
165
     */
166 1
    public function main()
167
    {
168 1
        if ($this->getOwningTarget()->getName() === "") {
169 0
            $this->log("Cowardly refusing to call target '{$this->subTarget}' from the root", Project::MSG_WARN);
170 0
            return;
171
        }
172

173 1
        $this->log("Running PhingCallTask for target '" . $this->subTarget . "'", Project::MSG_DEBUG);
174 1
        if ($this->callee === null) {
175 0
            $this->init();
176
        }
177

178 1
        if ($this->subTarget === null) {
179 1
            throw new BuildException("Attribute target is required.", $this->getLocation());
180
        }
181

182 1
        $this->callee->setPhingFile($this->project->getProperty("phing.file"));
183 1
        $this->callee->setTarget($this->subTarget);
184 1
        $this->callee->setInheritAll($this->inheritAll);
185 1
        $this->callee->setInheritRefs($this->inheritRefs);
186 1
        $this->callee->main();
187
    }
188
}

Read our documentation on viewing source code .

Loading