ConsoleReader.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /*
  3. * $Id: ConsoleReader.php 905 2010-10-05 16:28:03Z mrook $
  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. include_once 'phing/system/io/Reader.php';
  22. /**
  23. * Convenience class for reading console input.
  24. *
  25. * @author Hans Lellelid <hans@xmpl.org>
  26. * @author Matthew Hershberger <matthewh@lightsp.com>
  27. * @version $Revision: 905 $
  28. * @package phing.system.io
  29. */
  30. class ConsoleReader extends Reader {
  31. function readLine() {
  32. $out = fgets(STDIN); // note: default maxlen is 1kb
  33. $out = rtrim($out);
  34. return $out;
  35. }
  36. /**
  37. *
  38. * @param int $len Num chars to read.
  39. * @return string chars read or -1 if eof.
  40. */
  41. function read($len = null) {
  42. $out = fread(STDIN, $len);
  43. return $out;
  44. // FIXME
  45. // read by chars doesn't work (yet?) with PHP stdin. Maybe
  46. // this is just a language feature, maybe there's a way to get
  47. // ability to read chars w/o <enter> ?
  48. }
  49. function close() {
  50. // STDIN is always open
  51. }
  52. function open() {
  53. // STDIN is always open
  54. }
  55. /**
  56. * Whether eof has been reached with stream.
  57. * @return boolean
  58. */
  59. function eof() {
  60. return feof(STDIN);
  61. }
  62. /**
  63. * Returns path to file we are reading.
  64. * @return string
  65. */
  66. function getResource() {
  67. return "console";
  68. }
  69. }