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
 * @author Siad Ardroumli <siad.ardroumli@gmail.com>
22
 * @package phing.system.util
23
 */
24
class XMLChild implements DynamicConfigurator
25
{
26
    /**
27
     * @var DOMElement
28
     */
29
    private $e;
30
    /**
31
     * @var DOMDocument
32
     */
33
    private $d;
34
    /**
35
     * @var DOMDocumentFragment
36
     */
37
    private $f;
38
    /**
39
     * @var Project
40
     */
41
    private $p;
42

43
    /**
44
     * XMLChild constructor.
45
     * @param Project $p
46
     * @param DOMDocument $d
47
     * @param DOMDocumentFragment $f
48
     * @param DOMElement $e
49
     */
50 1
    public function __construct(Project $p, \DOMDocument $d, \DOMDocumentFragment $f, \DOMElement $e)
51
    {
52 1
        $this->p = $p;
53 1
        $this->d = $d;
54 1
        $this->f = $f;
55 1
        $this->e = $e;
56
    }
57

58
    /**
59
     * Add nested text.
60
     * @param string $s the text to add
61
     */
62 0
    public function addText(string $s): void
63
    {
64 0
        $s = $this->p->replaceProperties($s);
65
        //only text nodes that are non null after property expansion are added
66 0
        if ($s !== null && trim($s) !== '') {
67 0
            $t = $this->d->createTextNode(trim($s));
68 0
            $this->e->appendChild($t);
69
        }
70
    }
71

72 1
    public function setDynamicAttribute(string $name, string $value): void
73
    {
74 1
        $this->e->setAttribute($name, $value);
75
    }
76

77
    /**
78
     * @inheritDoc
79
     */
80 1
    public function customChildCreator($elementName, Project $project)
81
    {
82 1
        $e2 = $this->d->createElement($elementName);
83

84 1
        $this->e->appendChild($e2);
85 1
        return new self($this->p, $this->d, $this->f, $e2);
86
    }
87
}

Read our documentation on viewing source code .

Loading