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
|
|
* Expands Phing Properties, if any, in the data.
|
22
|
|
* <p>
|
23
|
|
* Example:<br>
|
24
|
|
* <pre><expandproperties/></pre>
|
25
|
|
* Or:
|
26
|
|
* <pre><filterreader classname="phing.filters.ExpandProperties'/></pre>
|
27
|
|
*
|
28
|
|
* @author Yannick Lecaillez <yl@seasonfive.com>
|
29
|
|
* @author Hans Lellelid <hans@xmpl.org>
|
30
|
|
* @see BaseFilterReader
|
31
|
|
* @package phing.filters
|
32
|
|
*/
|
33
|
|
class ExpandProperties extends BaseFilterReader implements ChainableReader
|
34
|
|
{
|
35
|
|
/**
|
36
|
|
* Returns the filtered stream.
|
37
|
|
* The original stream is first read in fully, and the Phing properties are expanded.
|
38
|
|
*
|
39
|
|
* @param int $len
|
40
|
|
* @return mixed the filtered stream, or -1 if the end of the resulting stream has been reached.
|
41
|
|
*
|
42
|
|
* @throws IOException if the underlying stream throws an IOException
|
43
|
|
* during reading
|
44
|
|
*/
|
45
|
1
|
public function read($len = null)
|
46
|
|
{
|
47
|
1
|
$buffer = $this->in->read($len);
|
48
|
|
|
49
|
1
|
if ($buffer === -1) {
|
50
|
1
|
return -1;
|
51
|
|
}
|
52
|
|
|
53
|
|
/**
|
54
|
|
* @var Project $project
|
55
|
|
*/
|
56
|
1
|
$project = $this->getProject();
|
57
|
1
|
$buffer = $project->replaceProperties($buffer);
|
58
|
|
|
59
|
1
|
return $buffer;
|
60
|
|
}
|
61
|
|
|
62
|
|
/**
|
63
|
|
* Creates a new ExpandProperties filter using the passed in
|
64
|
|
* Reader for instantiation.
|
65
|
|
*
|
66
|
|
* @param Reader $reader A Reader object providing the underlying stream.
|
67
|
|
* Must not be <code>null</code>.
|
68
|
|
*
|
69
|
|
* @return ExpandProperties A new filter based on this configuration, but filtering
|
70
|
|
* the specified reader
|
71
|
|
*/
|
72
|
1
|
public function chain(Reader $reader): Reader
|
73
|
|
{
|
74
|
1
|
$newFilter = new self($reader);
|
75
|
1
|
$newFilter->setProject($this->getProject());
|
76
|
|
|
77
|
1
|
return $newFilter;
|
78
|
|
}
|
79
|
|
}
|