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
|
|
* Assembles the constants declared in a PHP class in
|
22
|
|
* <code>key1=value1(PHP_EOL)key2=value2</code>
|
23
|
|
* format.
|
24
|
|
*
|
25
|
|
* @author Siad Ardroumli <siad.ardroumli@gmail.com>
|
26
|
|
* @package phing.filters
|
27
|
|
*/
|
28
|
|
class ClassConstants extends BaseFilterReader implements ChainableReader
|
29
|
|
{
|
30
|
|
private $test = '';
|
31
|
|
|
32
|
|
/**
|
33
|
|
* Returns the filtered stream.
|
34
|
|
*
|
35
|
|
* @param int $len
|
36
|
|
* @return mixed the filtered stream, or -1 if the end of the resulting stream has been reached.
|
37
|
|
*
|
38
|
|
* @throws IOException if the underlying stream throws an IOException
|
39
|
|
* during reading
|
40
|
|
*/
|
41
|
1
|
public function read($len = null)
|
42
|
|
{
|
43
|
1
|
$buffer = $this->in->read();
|
44
|
|
|
45
|
1
|
if ($buffer === -1) {
|
46
|
0
|
return -1;
|
47
|
|
}
|
48
|
|
|
49
|
1
|
$classes = get_declared_classes();
|
50
|
1
|
eval($buffer);
|
51
|
1
|
$newClasses = array_diff(get_declared_classes(), $classes);
|
52
|
|
|
53
|
1
|
$sb = '';
|
54
|
1
|
foreach ($newClasses as $name) {
|
55
|
1
|
$clazz = new ReflectionClass($name);
|
56
|
1
|
foreach ($clazz->getConstants() as $key => $value) {
|
57
|
1
|
$sb .= $key . '=' . $value . PHP_EOL;
|
58
|
|
}
|
59
|
|
}
|
60
|
|
|
61
|
1
|
return $sb;
|
62
|
|
}
|
63
|
|
|
64
|
|
/**
|
65
|
|
* Creates a new ExpandProperties filter using the passed in
|
66
|
|
* Reader for instantiation.
|
67
|
|
*
|
68
|
|
* @param Reader $reader A Reader object providing the underlying stream.
|
69
|
|
* Must not be <code>null</code>.
|
70
|
|
*
|
71
|
|
* @return ExpandProperties A new filter based on this configuration, but filtering
|
72
|
|
* the specified reader
|
73
|
|
*/
|
74
|
1
|
public function chain(Reader $reader): Reader
|
75
|
|
{
|
76
|
1
|
return new self($reader);
|
77
|
|
}
|
78
|
|
}
|