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
 * Convenience class for reading console input.
22
 *
23
 * @author  Hans Lellelid <hans@xmpl.org>
24
 * @author  Matthew Hershberger <matthewh@lightsp.com>
25
 * @package phing.system.io
26
 */
27
class ConsoleReader extends Reader
28
{
29

30
    /**
31
     * @return string
32
     */
33 0
    public function readLine()
34
    {
35 0
        $out = fgets(STDIN); // note: default maxlen is 1kb
36 0
        $out = rtrim($out);
37

38 0
        return $out;
39
    }
40

41
    /**
42
     *
43
     * @param  int $len Num chars to read.
44
     * @return string chars read or -1 if eof.
45
     */
46 0
    public function read($len = null)
47
    {
48 0
        $out = fread(STDIN, $len);
49

50 0
        return $out;
51
        // FIXME
52
        // read by chars doesn't work (yet?) with PHP stdin.  Maybe
53
        // this is just a language feature, maybe there's a way to get
54
        // ability to read chars w/o <enter> ?
55
    }
56

57 0
    public function close()
58
    {
59
        // STDIN is always open
60
    }
61

62 0
    public function open()
63
    {
64
        // STDIN is always open
65
    }
66

67
    /**
68
     * Whether eof has been reached with stream.
69
     *
70
     * @return boolean
71
     */
72 0
    public function eof()
73
    {
74 0
        return feof(STDIN);
75
    }
76

77
    /**
78
     * Returns path to file we are reading.
79
     *
80
     * @return string
81
     */
82 0
    public function getResource()
83
    {
84 0
        return "console";
85
    }
86
}

Read our documentation on viewing source code .

Loading