Path

ez components / documentation / api reference / 2007.1.1 / consoletools


eZ Components 2007.1.1

ConsoleTools: ezcConsoleQuestionDialog

[ Tutorial ] [ Class tree ] [ Element index ] [ ChangeLog ] [ Credits ]

Class: ezcConsoleQuestionDialog

Dialog class to ask a simple question. [source]

Implemented Interfaces

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.

Properties

ezcConsoleQuestionDialogOptions read/write  $options
Options for the dialog.
ezcConsoleOutput read/write  $output
Output object for displaying the dialog.

Member Variables

protected array $properties = array(
"options" => null,
"output" => null,
)

Properties
protected mixed $result
Dialog result

Method Summary

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.
public static ezcConsoleQuestionDialog YesNoQuestion( $out, $questionString, [$default = null] )
Returns a ready to use yes/no question dialog.

Methods

__construct

void __construct( ezcConsoleOutput $output, [ezcConsoleQuestionDialogOptions $options = null] )
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.

Parameters

Name Type Description
$output ezcConsoleOutput Output object.
$options ezcConsoleQuestionDialogOptions Options.

display

void display( )
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.

getResult

mixed getResult( )
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.

Throws

ClassDescription
ezcConsoleNoValidDialogResultException if no valid result was retreived, yet.

hasValidResult

bool hasValidResult( )
Returns if the dialog retrieved a valid result.
If a valid result has already been received, this method returns true, otherwise false.

reset

void reset( )
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.

YesNoQuestion

ezcConsoleQuestionDialog YesNoQuestion( ezcConsoleOutput $out, string $questionString, [string $default = null] )
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.
1.  // Would you like to proceed? (y/n)
2.   $dialog ezcConsoleDialog$out"Would you like to proceed?" );
3.  
4.  // Would you like to proceed? (y/n) [n]
5.   $dialog ezcConsoleDialog$out"Would you like to proceed?""n" );

Parameters

Name Type Description
$out ezcConsoleOutput Output object.
$questionString string Question string.
$default string "y" or "n", if default value is desired.

Last updated: Wed, 28 Nov 2007