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
 * A PhingFilterReader is a wrapper class that encloses the className
22
 * and configuration of a Configurable FilterReader.
23
 *
24
 * @author  Yannick Lecaillez <yl@seasonfive.com>
25
 * @see     FilterReader
26
 * @package phing.types
27
 */
28
class PhingFilterReader extends DataType
29
{
30
    private $className;
31
    private $parameters = [];
32

33
    /** @var Path */
34
    private $classPath;
35

36
    /**
37
     * @param $className
38
     */
39 1
    public function setClassName($className)
40
    {
41 1
        $this->className = $className;
42
    }
43

44 1
    public function getClassName()
45
    {
46 1
        return $this->className;
47
    }
48

49
    /**
50
     * Set the classpath to load the FilterReader through (attribute).
51
     *
52
     * @param  Path $classpath
53
     * @throws BuildException
54
     */
55 0
    public function setClasspath(Path $classpath)
56
    {
57 0
        if ($this->isReference()) {
58 0
            throw $this->tooManyAttributes();
59
        }
60 0
        if ($this->classPath === null) {
61 0
            $this->classPath = $classpath;
62
        } else {
63 0
            $this->classPath->append($classpath);
64
        }
65
    }
66

67
    /*
68
     * Set the classpath to load the FilterReader through (nested element).
69
    */
70
    /**
71
     * @return Path
72
     * @throws BuildException
73
     */
74 0
    public function createClasspath()
75
    {
76 0
        if ($this->isReference()) {
77 0
            throw $this->noChildrenAllowed();
78
        }
79 0
        if ($this->classPath === null) {
80 0
            $this->classPath = new Path($this->project);
81
        }
82

83 0
        return $this->classPath->createPath();
84
    }
85

86 1
    public function getClasspath()
87
    {
88 1
        return $this->classPath;
89
    }
90

91
    /**
92
     * @param Reference $r
93
     * @throws BuildException
94
     */
95 0
    public function setClasspathRef(Reference $r)
96
    {
97 0
        if ($this->isReference()) {
98 0
            throw $this->tooManyAttributes();
99
        }
100 0
        $o = $this->createClasspath();
101 0
        $o->setRefid($r);
102
    }
103

104
    /**
105
     * @param Parameter $param
106
     */
107 0
    public function addParam(Parameter $param)
108
    {
109 0
        $this->parameters[] = $param;
110
    }
111

112 1
    public function createParam()
113
    {
114 1
        $num = array_push($this->parameters, new Parameter());
115

116 1
        return $this->parameters[$num - 1];
117
    }
118

119
    /**
120
     * @return array
121
     */
122 1
    public function getParams()
123
    {
124
        // We return a COPY
125 1
        $ret = [];
126 1
        for ($i = 0, $size = count($this->parameters); $i < $size; $i++) {
127 1
            $ret[] = clone $this->parameters[$i];
128
        }
129

130 1
        return $ret;
131
    }
132

133
    /*
134
     * Makes this instance in effect a reference to another PhingFilterReader
135
     * instance.
136
     *
137
     * <p>You must not set another attribute or nest elements inside
138
     * this element if you make it a reference.</p>
139
     *
140
     * @param Reference $r the reference to which this instance is associated
141
     * @throws BuildException if this instance already has been configured.
142
    */
143
    /**
144
     * @param Reference $r
145
     * @throws BuildException
146
     */
147 0
    public function setRefid(Reference $r)
148
    {
149 0
        if ((count($this->parameters) !== 0) || ($this->className !== null)) {
150 0
            throw $this->tooManyAttributes();
151
        }
152 0
        $o = $r->getReferencedObject($this->getProject());
153 0
        if ($o instanceof PhingFilterReader) {
154 0
            $this->setClassName($o->getClassName());
155 0
            $this->setClasspath($o->getClasspath());
156 0
            foreach ($o->getParams() as $p) {
157 0
                $this->addParam($p);
158
            }
159
        } else {
160 0
            $msg = $r->getRefId() . " doesn\'t refer to a PhingFilterReader";
161 0
            throw new BuildException($msg);
162
        }
163

164 0
        parent::setRefid($r);
165
    }
166
}

Read our documentation on viewing source code .

Loading