Passed
Push — main ( 6d6278...7007dc )
by Michiel
06:36
created

XsltTask::setResolveDocumentExternals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * This software consists of voluntary contributions made by many individuals
17
 * and is licensed under the LGPL. For more information please see
18
 * <http://phing.info>.
19
 */
20
21
namespace Phing\Task\System;
22
23
use Phing\Filter\XsltFilter;
24
use Phing\Filter\XsltParam;
25
use Phing\Io\File;
26
use Phing\Project;
27
use Phing\Type\FilterChain;
28
29
/**
30
 * Implements an XSLT processing filter while copying files.
31
 *
32
 * This is a shortcut for calling the <copy> task with the XSLTFilter used
33
 * in the <filterchains> section.
34
 *
35
 * @author  Andreas Aderhold, [email protected]
36
 */
37
class XsltTask extends CopyTask
38
{
39
    /**
40
     * @var XsltFilter object that we use to handle transformation
41
     */
42
    private $xsltFilter;
43
44
    /**
45
     * @var XsltParam[] parameters to pass to XSLT processor
46
     */
47
    private $parameters = [];
48
49
    /**
50
     * Setup the filterchains w/ XSLTFilter that we will use while copying the files.
51
     */
52 1
    public function init()
53
    {
54 1
        $xf = new XsltFilter();
55 1
        $chain = new FilterChain($this->getProject());
56 1
        $chain->addXsltFilter($xf);
57 1
        $this->addFilterChain($chain);
58 1
        $this->xsltFilter = $xf;
59
    }
60
61
    /**
62
     * Set any XSLT Param and invoke CopyTask::main().
63
     *
64
     * @see CopyTask::main()
65
     */
66 1
    public function main()
67
    {
68 1
        $this->log('Doing XSLT transformation using stylesheet ' . $this->xsltFilter->getStyle(), Project::MSG_VERBOSE);
69 1
        $this->xsltFilter->setParams($this->parameters);
70 1
        parent::main();
71
    }
72
73 1
    public function setHtml(bool $isHtml)
74
    {
75 1
        $this->xsltFilter->setHtml($isHtml);
76
    }
77
78
    /**
79
     * Set the stylesheet to use.
80
     */
81 1
    public function setStyle(File $style)
82
    {
83 1
        $this->xsltFilter->setStyle($style);
84
    }
85
86
    /**
87
     * Whether to resolve entities in the XML document.
88
     *
89
     * @since 2.4
90
     */
91
    public function setResolveDocumentExternals(bool $resolveExternals)
92
    {
93
        $this->xsltFilter->setResolveDocumentExternals($resolveExternals);
94
    }
95
96
    /**
97
     * Whether to resolve entities in the stylesheet.
98
     *
99
     * @since 2.4
100
     */
101
    public function setResolveStylesheetExternals(bool $resolveExternals)
102
    {
103
        $this->xsltFilter->setResolveStylesheetExternals($resolveExternals);
104
    }
105
106
    /**
107
     * Support nested <param> tags using XSLTParam class.
108
     *
109
     * @return XsltParam
110
     */
111
    public function createParam()
112
    {
113
        $num = array_push($this->parameters, new XsltParam());
114
115
        return $this->parameters[$num - 1];
116
    }
117
}
118