Zeta Components - high quality PHP components

Zeta Components Manual :: Docs For Class ezcConsoleQuestionDialogMappingValidator

ConsoleTools::ezcConsoleQuestionDialogMappingValidator

Class ezcConsoleQuestionDialogMappingValidator

Validator class to map certain results to others.

This validator class, for ezcConsoleQuestionDialog objects, validates a given result against a set of predefined values, exactly like ezcConsoleQuestionDialogCollectionValidator does, but allows in addition to map certain results to other results. The $map property contains an array of mappings that are checked before a received result is validated. If a mapping matches, the received result is converted to the mapping target before being validated.

A valid $map looks like this:

  1.       array(
  2.           'yes' => 'y',
  3.           'no'  => 'n',
  4.           '1'   => 'y',
  5.           '0'   => 'n'
  6.       )
While the corresponding collection of valid answers would look like this:
  1.       array(
  2.           'y', 'n'
  3.       )
If the answer 'yes' is received by the validator, it is mapped to 'y', therefore considered valid and 'y' is returned as the received value.

Source for this file: /ConsoleTools/src/dialog/validators/question_dialog_mapping.php

ezcConsoleQuestionDialogCollectionValidator
   |
   --ezcConsoleQuestionDialogMappingValidator
Version:   //autogen//

Properties

array(string) read/write $collection
The collection of valid answers.
int read/write $conversion
ezcConsoleDialogValidator::CONVERT_NONE (default) or ezcConsoleDialogValidator::CONVERT_LOWER or ezcConsoleDialogValidator::CONVERT_UPPER.
mixed read/write $default
Default value.
array(string=>string) read/write $map
Mapping of answers to valid answers (e.g. array('yes' => 'y') to map 'yes' to 'y' while 'y' must be in $collection).

Inherited Member Variables

From ezcConsoleQuestionDialogCollectionValidator
protected ezcConsoleQuestionDialogCollectionValidator::$properties

Method Summary

public void __construct( $collection , [ $default = null] , [ $conversion = self::CONVERT_NONE] , [ $map = array()] )
Creates a new question dialog mapping validator.
public mixed fixup( $result )
Returns a fixed version of the result, if possible.

Inherited Methods

From ezcConsoleQuestionDialogCollectionValidator
public void ezcConsoleQuestionDialogCollectionValidator::__construct()
Creates a new question dialog collection validator.
public mixed ezcConsoleQuestionDialogCollectionValidator::fixup()
Returns a fixed version of the result, if possible.
public string ezcConsoleQuestionDialogCollectionValidator::getResultString()
Returns a string representing valid results.
public bool ezcConsoleQuestionDialogCollectionValidator::validate()
Returns if the given result is valid.

Methods

__construct

void __construct( $collection , [mixed $default = null] , [int $conversion = self::CONVERT_NONE] , [ $map = array()] )

Creates a new question dialog mapping validator.

Creates a new question dialog mapping validator, which validates the result specified by the user against an array of valid results ($collection). If not value is provided by the user a possibly set $default value is used instead. The $conversion parameter can optionally define a conversion to be performed on the result before validating it. Valid conversions are defined by the CONVERT_* constants in this class.

While this functionality is already provided by ezcConsoleQuestionDialogCollectionValidator, the additional $map paramater allows the sepcification of a map of result values. These mapping is then checked for matches, before a received answer is validated against the collection.

Parameters:
Name Type Description
$collection array(string) The collection of valid results.
$default mixed Optional default value.
$conversion int CONVERT_* constant.
$map array(string=>string)
Redefinition of:
Method Description
ezcConsoleQuestionDialogCollectionValidator::__construct() Creates a new question dialog collection validator.

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.
Redefinition of:
Method Description
ezcConsoleQuestionDialogCollectionValidator::fixup() Returns a fixed version of the result, if possible.
Documentation generated by phpDocumentor 1.4.3