|
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\Io; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Convenience class for reading console input. |
|
25
|
|
|
* |
|
26
|
|
|
* @author Hans Lellelid <[email protected]> |
|
27
|
|
|
* @author Matthew Hershberger <[email protected]> |
|
28
|
|
|
*/ |
|
29
|
|
|
class ConsoleReader extends Reader |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* @return string |
|
33
|
|
|
*/ |
|
34
|
|
|
public function readLine() |
|
35
|
|
|
{ |
|
36
|
|
|
$out = fgets(STDIN); // note: default maxlen is 1kb |
|
37
|
|
|
|
|
38
|
|
|
return rtrim($out); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param int $len num chars to read |
|
43
|
|
|
* |
|
44
|
|
|
* @return string chars read or -1 if eof |
|
45
|
|
|
*/ |
|
46
|
|
|
public function read($len = null) |
|
47
|
|
|
{ |
|
48
|
|
|
return fread(STDIN, $len); |
|
|
|
|
|
|
49
|
|
|
// FIXME |
|
50
|
|
|
// read by chars doesn't work (yet?) with PHP stdin. Maybe |
|
51
|
|
|
// this is just a language feature, maybe there's a way to get |
|
52
|
|
|
// ability to read chars w/o <enter> ? |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function close() |
|
56
|
|
|
{ |
|
57
|
|
|
// STDIN is always open |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function open() |
|
61
|
|
|
{ |
|
62
|
|
|
// STDIN is always open |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Whether eof has been reached with stream. |
|
67
|
|
|
* |
|
68
|
|
|
* @return bool |
|
69
|
|
|
*/ |
|
70
|
|
|
public function eof() |
|
71
|
|
|
{ |
|
72
|
|
|
return feof(STDIN); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Returns path to file we are reading. |
|
77
|
|
|
* |
|
78
|
|
|
* @return string |
|
79
|
|
|
*/ |
|
80
|
|
|
public function getResource() |
|
81
|
|
|
{ |
|
82
|
|
|
return 'console'; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|