Dialog class to ask a simple question.
This dialog outputs a certain string to the user and requests a line of input. This is commonly used to ask questions like "Do you want to proceed?" and retrieve an answer like "y" for yes or "n" for no.
The behaviour of this dialog is defined by an instance of ezcConsoleQuestionDialogOptions.
Source for this file: /ConsoleTools/src/dialog/question_dialog.php
Version: | //autogen// |
ezcConsoleQuestionDialogOptions | read/write |
$options
Options for the dialog. |
ezcConsoleOutput | read/write |
$output
Output object for displaying the dialog. |
protected array |
$properties
= array(
Properties |
protected mixed |
$result
Dialog result |
public static ezcConsoleQuestionDialog |
YesNoQuestion(
$out
, $questionString
, [ $default
= null] )
Returns a ready to use yes/no question dialog. |
public void |
__construct(
$output
, [ $options
= null] )
Creates a new question dialog. |
public void |
display(
)
Displays the dialog and retreives a value from the user. |
public mixed |
getResult(
)
Returns the result retrieved. |
public bool |
hasValidResult(
)
Returns if the dialog retrieved a valid result. |
public void |
reset(
)
Reset the dialog. |
Returns a ready to use yes/no question dialog.
Returns a question dialog, which requests the answers "y" for "yes" or "n" for "no" from the user. The answer is converted to lower-case.
Name | Type | Description |
---|---|---|
$out |
ezcConsoleOutput | Output object. |
$questionString |
string | Question string. |
$default |
string | "y" or "n", if default value is desired. |
Creates a new question dialog.
Creates a new menu dialog to be displayed to the user. All behaviour is defined through the $options parameter. The $output parameter is used to display the dialog in the display() method.
Name | Type | Description |
---|---|---|
$output |
ezcConsoleOutput | Output object. |
$options |
ezcConsoleQuestionDialogOptions | Options. |
Displays the dialog and retreives a value from the user.
Displays the dialog and retreives the desired answer from the user. If the a valid result is retrieved, it can be obtained using getResult(). The method hasValidResult() can be used to check if a valid result is available.
Type | Description |
---|---|
ezcConsoleDialogAbortException |
if the user closes STDIN using <CTRL>-D. |
Method | Description |
---|---|
ezcConsoleDialog::display() |
Displays the dialog. |
Returns the result retrieved.
If no valid result was retreived, yet, this method should throw an ezcConsoleNoValidDialogResultException.
If no valid result was retreived, yet, this method throws an ezcConsoleNoValidDialogResultException. Use hasValidResult() to avoid this.
Type | Description |
---|---|
ezcDialogNoValidResultException |
if this method is called without a valid result being retrieved by the object. Use hasValidResult() to avoid this exception. |
Method | Description |
---|---|
ezcConsoleDialog::getResult() |
Returns the result retrieved. |
Returns if the dialog retrieved a valid result.
If a valid result has already been received, this method returns true, otherwise false.
Method | Description |
---|---|
ezcConsoleDialog::hasValidResult() |
Returns if the dialog retrieved a valid result. |
Reset the dialog.
Resets a possibly received result and all changes made to the dialog during display(). After that, the dialog can be re-used. All option values are kept.
Method | Description |
---|---|
ezcConsoleDialog::reset() |
Resets the dialog to its initial state. |