| 1 |
lars |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
* $Id: ConsoleReader.php 325 2007-12-20 15:44:58Z hans $
|
|
|
4 |
*
|
|
|
5 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
6 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
7 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
8 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
9 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
10 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
11 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
12 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
13 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
14 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
15 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
16 |
*
|
|
|
17 |
* This software consists of voluntary contributions made by many individuals
|
|
|
18 |
* and is licensed under the LGPL. For more information please see
|
|
|
19 |
* <http://phing.info>.
|
|
|
20 |
*/
|
|
|
21 |
|
|
|
22 |
include_once 'phing/system/io/Reader.php';
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* Convenience class for reading console input.
|
|
|
26 |
*
|
|
|
27 |
* @author Hans Lellelid <hans@xmpl.org>
|
|
|
28 |
* @author Matthew Hershberger <matthewh@lightsp.com>
|
|
|
29 |
* @version $Revision: 1.4 $
|
|
|
30 |
* @package phing.system.io
|
|
|
31 |
*/
|
|
|
32 |
class ConsoleReader extends Reader {
|
|
|
33 |
|
|
|
34 |
function readLine() {
|
|
|
35 |
|
|
|
36 |
$out = fgets(STDIN); // note: default maxlen is 1kb
|
|
|
37 |
$out = rtrim($out);
|
|
|
38 |
|
|
|
39 |
return $out;
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
*
|
|
|
44 |
* @param int $len Num chars to read.
|
|
|
45 |
* @return string chars read or -1 if eof.
|
|
|
46 |
*/
|
|
|
47 |
function read($len = null) {
|
|
|
48 |
|
|
|
49 |
$out = fread(STDIN, $len);
|
|
|
50 |
|
|
|
51 |
|
|
|
52 |
return $out;
|
|
|
53 |
// FIXME
|
|
|
54 |
// read by chars doesn't work (yet?) with PHP stdin. Maybe
|
|
|
55 |
// this is just a language feature, maybe there's a way to get
|
|
|
56 |
// ability to read chars w/o <enter> ?
|
|
|
57 |
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
function close() {
|
|
|
61 |
// STDIN is always open
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
function open() {
|
|
|
65 |
// STDIN is always open
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
/**
|
|
|
69 |
* Whether eof has been reached with stream.
|
|
|
70 |
* @return boolean
|
|
|
71 |
*/
|
|
|
72 |
function eof() {
|
|
|
73 |
return feof(STDIN);
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
/**
|
|
|
77 |
* Returns path to file we are reading.
|
|
|
78 |
* @return string
|
|
|
79 |
*/
|
|
|
80 |
function getResource() {
|
|
|
81 |
return "console";
|
|
|
82 |
}
|
|
|
83 |
}
|
|
|
84 |
|