PHP Class Webmozart\Console\Api\IO\Input

This class wraps an input stream and adds convenience functionality for reading that stream.
Since: 1.0
Author: Bernhard Schussek ([email protected])
Show file Open project: webmozart/console Class Usage Examples

Public Methods

Method Description
__construct ( Webmozart\Console\Api\IO\InputStream $stream ) Creates an input for the given input stream.
close ( ) Closes the input.
getStream ( ) : Webmozart\Console\Api\IO\InputStream Returns the underlying stream.
isClosed ( ) : boolean Returns whether the input is closed.
isInteractive ( ) : boolean Returns whether the user may be asked for input.
read ( integer $length, string $default = null ) : string Reads the given amount of characters from the input stream.
readLine ( string $default = null, integer $length = null ) : string Reads a line from the input stream.
setInteractive ( boolean $interactive ) Enables or disables interaction with the user.
setStream ( Webmozart\Console\Api\IO\InputStream $stream ) Sets the underlying stream.

Method Details

__construct() public method

Creates an input for the given input stream.
public __construct ( Webmozart\Console\Api\IO\InputStream $stream )
$stream Webmozart\Console\Api\IO\InputStream The input stream.

close() public method

Closes the input.
public close ( )

getStream() public method

Returns the underlying stream.
public getStream ( ) : Webmozart\Console\Api\IO\InputStream
return Webmozart\Console\Api\IO\InputStream The input stream.

isClosed() public method

Returns whether the input is closed.
public isClosed ( ) : boolean
return boolean Returns `true` if the input is closed and `false` otherwise.

isInteractive() public method

Returns whether the user may be asked for input.
public isInteractive ( ) : boolean
return boolean Returns `true` if the user may be asked for input and `false` otherwise.

read() public method

Reads the given amount of characters from the input stream.
public read ( integer $length, string $default = null ) : string
$length integer The number of characters to read.
$default string The default to return if interaction is disabled.
return string The characters read from the input stream.

readLine() public method

Reads a line from the input stream.
public readLine ( string $default = null, integer $length = null ) : string
$default string The default to return if interaction is disabled.
$length integer The maximum number of characters to read. If `null`, all characters up to the first newline are returned.
return string The characters read from the input stream.

setInteractive() public method

Enables or disables interaction with the user.
public setInteractive ( boolean $interactive )
$interactive boolean Whether the inputmay interact with the user. If set to `false`, all calls to {@link read()} and {@link readLine()} will immediately return the default value.

setStream() public method

Sets the underlying stream.
public setStream ( Webmozart\Console\Api\IO\InputStream $stream )
$stream Webmozart\Console\Api\IO\InputStream The input stream.