ConsoleTools: ezcConsoleMenuDialogDefaultValidator
[ ]
[ ]
[ ]
[ ]
[ ]
Class: ezcConsoleMenuDialogDefaultValidator
|
Default validator for ezcConsoleMenuDialog. [
source]
Implemented Interfaces
This dialog contains a set of menu entries, defined in the $elements property. The result, provided by the user, is checked against the keys of this array. A conversion can be specified to relax the rules for validation (like coverting the result to lower case first). For possibly conversions see the CONVERT_* constants in this class If the user does not provide an answer, a possibly set default value is used.
Properties
|
int |
read/write
|
$conversion
ezcConsoleDialogValidator::CONVERT_NONE (default) or ezcConsoleDialogValidator::CONVERT_LOWER or ezcConsoleDialogValidator::CONVERT_UPPER. |
|
string |
read/write
|
$default
The default value. |
|
array |
read/write
|
$elements
The elements of the menu. |
Member Variables
|
protected array |
$properties
= array( "elements" => array(),"default"=>null,"conversion"=>self::CONVERT_NONE,)
Properties |
Method Summary
|
public void |
__construct(
[$elements = array()], [$default = null], [$conversion = self::CONVERT_NONE] )
Creates a new menu default validator. |
|
public mixed |
fixup(
$result )
Returns a fixed version of the result, if possible. |
|
public array(string=>string) |
getElements(
)
Returns an array of the elements to display. |
|
public string |
getResultString(
)
Returns a string representing the default value. |
|
public bool |
validate(
$result )
Returns if the given result is valid. |
Methods
__construct
void __construct(
[
$elements = array()], [mixed
$default = null], [int
$conversion = self::CONVERT_NONE] )
Creates a new menu default validator.
Creates a validator specified by the given parameters. The $elements array specifies the possible menu items to select from. The item identifier (the key of the array) is used to validate the result. The assigned text is displayed as the menu item text. If no result is provided and an optionally provided default value is used. The $conversion parameter can be used to get a conversion applied to the result before validating it.
Parameters
| Name |
Type |
Description |
$elements |
array |
The elements of the menu. |
$default |
mixed |
The default value. |
$conversion |
int |
The conversion to apply. |
fixup
mixed fixup(
mixed
$result )
Returns a fixed version of the result, if possible.
Converts the given result according to the conversion defined in the $conversion property.
Parameters
| Name |
Type |
Description |
$result |
mixed |
The received result. |
getElements
array(string=>string) getElements(
)
Returns an array of the elements to display.
getResultString
string getResultString(
)
Returns a string representing the default value.
For example "[y]" to indicate that "y" is the preselected result and will be chosen if no result is provided.
validate
bool validate(
mixed
$result )
Returns if the given result is valid.
Checks if the given result is a valid key in the $elements property.
Parameters
| Name |
Type |
Description |
$result |
mixed |
The received result. |
Last updated: Tue, 02 Dec 2008