Library
Class

Library\CommandLine\Stream

class Stream

Command line streams manager

Use this class to write on STDOUT or STDERR and read from STDIN.

Properties

$stream STDOUT stream for writing
$error STDERR stream for writing
$input STDIN stream for reading

Methods

__construct()

The three streams are initiated

void __exit(string $str = null)

Exit the script execution

void error(string $str, int $status = 1, bool $new_line = true)

Write a message on STDERR and exit with an error status

void write(string $str, bool $new_line = true)

Write a message on STDOUT

void prompt(string $str)

Write a message on STDOUT and wait for a user input on STDIN

string getUserResponse()

Get last user input on STDIN

Details

at line 66
public __construct()

The three streams are initiated

They are created with the defaults STDIN, STDOUT and STDERR if present or opened as file streams otherwise.

at line 79
public void __exit(string $str = null)

Exit the script execution

Parameters

string $str Optional string to write before exit

Return Value

void

at line 93
public void error(string $str, int $status = 1, bool $new_line = true)

Write a message on STDERR and exit with an error status

Parameters

string $str The error message string to write
int $status The error status for exit (default is 1) ; you can set it on 0 to not exit
bool $new_line Pass a new line befor exit (default is true)

Return Value

void

at line 107
public void write(string $str, bool $new_line = true)

Write a message on STDOUT

Parameters

string $str The error message string to write
bool $new_line Pass a new line befor exit (default is true)

Return Value

void

at line 119
public void prompt(string $str)

Write a message on STDOUT and wait for a user input on STDIN

Parameters

string $str The error message string to write

Return Value

void

at line 130
public string getUserResponse()

Get last user input on STDIN

Return Value

string The last user input from STDIN