Zend Framework  1.12
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Zend_Filter_Input Class Reference

Public Member Functions

 __construct ($filterRules, $validatorRules, array $data=null, array $options=null)
 
 addNamespace ($namespaces)
 
 addFilterPrefixPath ($prefix, $path)
 Add prefix path for all elements.
 
 addValidatorPrefixPath ($prefix, $path)
 Add prefix path for all elements.
 
 setPluginLoader (Zend_Loader_PluginLoader_Interface $loader, $type)
 Set plugin loaders for use with decorators and elements.
 
 getPluginLoader ($type)
 Retrieve plugin loader for given type.
 
 getMessages ()
 
 getErrors ()
 
 getInvalid ()
 
 getMissing ()
 
 getUnknown ()
 
 getEscaped ($fieldName=null)
 
 getUnescaped ($fieldName=null)
 
 __get ($fieldName)
 
 hasInvalid ()
 
 hasMissing ()
 
 hasUnknown ()
 
 hasValid ()
 
 isValid ($fieldName=null)
 
 __isset ($fieldName)
 
 process ()
 
 setData (array $data)
 
 setDefaultEscapeFilter ($escapeFilter)
 
 setOptions (array $options)
 
 setTranslator ($translator=null)
 Set translation object.
 
 getTranslator ()
 Return translation object.
 
 setDisableTranslator ($flag)
 Indicate whether or not translation should be disabled.
 
 translatorIsDisabled ()
 Is translation disabled?
 

Public Attributes

const ALLOW_EMPTY = 'allowEmpty'
 
const BREAK_CHAIN = 'breakChainOnFailure'
 
const DEFAULT_VALUE = 'default'
 
const MESSAGES = 'messages'
 
const ESCAPE_FILTER = 'escapeFilter'
 
const FIELDS = 'fields'
 
const FILTER = 'filter'
 
const FILTER_CHAIN = 'filterChain'
 
const MISSING_MESSAGE = 'missingMessage'
 
const INPUT_NAMESPACE = 'inputNamespace'
 
const VALIDATOR_NAMESPACE = 'validatorNamespace'
 
const FILTER_NAMESPACE = 'filterNamespace'
 
const NOT_EMPTY_MESSAGE = 'notEmptyMessage'
 
const PRESENCE = 'presence'
 
const PRESENCE_OPTIONAL = 'optional'
 
const PRESENCE_REQUIRED = 'required'
 
const RULE = 'rule'
 
const RULE_WILDCARD = '*'
 
const VALIDATE = 'validate'
 
const VALIDATOR = 'validator'
 
const VALIDATOR_CHAIN = 'validatorChain'
 
const VALIDATOR_CHAIN_COUNT = 'validatorChainCount'
 

Protected Member Functions

 _escapeRecursive ($data)
 
 _filter ()
 
 _filterRule (array $filterRule)
 
 _getDefaultEscapeFilter ()
 
 _getMissingMessage ($rule, $field)
 
 _getNotEmptyMessage ($rule, $field)
 
 _process ()
 
 _validate ()
 
 _validateRule (array $validatorRule)
 
 _getNotEmptyValidatorInstance ($validatorRule)
 Check a validatorRule for the presence of a NotEmpty validator instance.
 
 _getFilter ($classBaseName)
 
 _getValidator ($classBaseName)
 
 _getFilterOrValidator ($type, $classBaseName)
 

Protected Attributes

 $_data = array()
 
 $_filterRules = array()
 
 $_validatorRules = array()
 
 $_validFields = array()
 
 $_invalidMessages = array()
 
 $_invalidErrors = array()
 
 $_missingFields = array()
 
 $_unknownFields = array()
 
 $_defaultEscapeFilter = null
 
 $_loaders = array()
 
 $_defaults
 
 $_processed = false
 
 $_translator
 
 $_translatorDisabled = false
 

Constructor & Destructor Documentation

__construct (   $filterRules,
  $validatorRules,
array  $data = null,
array  $options = null 
)
Parameters
array$filterRules
array$validatorRules
array$dataOPTIONAL
array$optionsOPTIONAL

Member Function Documentation

__get (   $fieldName)
Parameters
string$fieldName
Returns
mixed
__isset (   $fieldName)
Parameters
string$fieldName
Returns
boolean
_escapeRecursive (   $data)
protected
Parameters
mixed$value
Returns
mixed
_filter ( )
protected
Returns
void

Make sure we have an array representing this filter chain. Don't typecast to (array) because it might be a Zend_Filter object

Filters are indexed by integer, metacommands are indexed by string. Pick out the filters.

Use defaults for filter metacommands.

Load all the filter classes and add them to the chain.

If the ruleName is the special wildcard rule, then apply the filter chain to all input data. Else just process the field named by the rule.

_filterRule ( array  $filterRule)
protected
Parameters
array$filterRule
Returns
void
_getDefaultEscapeFilter ( )
protected
_getFilter (   $classBaseName)
protected
Parameters
mixed$classBaseName
Returns
Zend_Filter_Interface
_getFilterOrValidator (   $type,
  $classBaseName 
)
protected
Parameters
string$type
mixed$classBaseName
Returns
Zend_Filter_Interface|Zend_Validate_Interface
Exceptions
Zend_Filter_Exception
_getMissingMessage (   $rule,
  $field 
)
protected
Parameters
string$rule
string$field
Returns
string
_getNotEmptyMessage (   $rule,
  $field 
)
protected
Returns
string
_getNotEmptyValidatorInstance (   $validatorRule)
protected

Check a validatorRule for the presence of a NotEmpty validator instance.

The purpose is to preserve things like a custom message, that may have been set on the validator outside Zend_Filter_Input.

Parameters
array$validatorRule
Returns
mixed false if none is found, Zend_Validate_NotEmpty instance if found
_getValidator (   $classBaseName)
protected
Parameters
mixed$classBaseName
Returns
Zend_Validate_Interface
_process ( )
protected
Returns
void
_validate ( )
protected
Returns
void

Special case: if there are no validators, treat all fields as valid.

Make sure we have an array representing this validator chain. Don't typecast to (array) because it might be a Zend_Validate object

Validators are indexed by integer, metacommands are indexed by string. Pick out the validators.

Use defaults for validation metacommands.

Load all the validator classes and add them to the chain.

we are changing the defaults here, this is alright if all subsequent validators are also a not empty validator, but it goes wrong if one of them is not AND is required!!! that is why we restore the default value at the end of this loop

If the ruleName is the special wildcard rule, then apply the validator chain to all input data. Else just process the field named by the rule.

Unset fields in $_data that have been added to other arrays. We have to wait until all rules have been processed because a given field may be referenced by multiple rules.

Anything left over in $_data is an unknown field.

_validateRule ( array  $validatorRule)
protected
Parameters
array$validatorRule
Returns
void

Get one or more data values from input, and check for missing fields. Apply defaults if fields are missing.

Todo:
according to this code default value can't be an array. It has to be reviewed

If any required fields are missing, break the loop.

Evaluate the inputs against the validator chain.

If we got this far, the inputs for this rule pass validation.

addFilterPrefixPath (   $prefix,
  $path 
)

Add prefix path for all elements.

Parameters
string$prefix
string$path
Returns
Zend_Filter_Input
addNamespace (   $namespaces)
Parameters
mixed$namespaces
Returns
Zend_Filter_Input
Deprecated:
since 1.5.0RC1 - use addFilterPrefixPath() or addValidatorPrefixPath instead.
addValidatorPrefixPath (   $prefix,
  $path 
)

Add prefix path for all elements.

Parameters
string$prefix
string$path
Returns
Zend_Filter_Input
getErrors ( )
Returns
array
getEscaped (   $fieldName = null)
Parameters
string$fieldNameOPTIONAL
Returns
mixed
getInvalid ( )
Returns
array
getMessages ( )
Returns
array
getMissing ( )
Returns
array
getPluginLoader (   $type)

Retrieve plugin loader for given type.

$type may be one of:

  • filter
  • validator

If a plugin loader does not exist for the given type, defaults are created.

Parameters
string$type'filter' or 'validate'
Returns
Zend_Loader_PluginLoader_Interface
Exceptions
Zend_Filter_Exceptionon invalid type
getTranslator ( )

Return translation object.

Returns
Zend_Translate_Adapter|null
getUnescaped (   $fieldName = null)
Parameters
string$fieldNameOPTIONAL
Returns
mixed
getUnknown ( )
Returns
array
hasInvalid ( )
Returns
boolean
hasMissing ( )
Returns
boolean
hasUnknown ( )
Returns
boolean
hasValid ( )
Returns
boolean
isValid (   $fieldName = null)
Parameters
string$fieldName
Returns
boolean
process ( )
setData ( array  $data)
Parameters
array$data
Returns
Zend_Filter_Input

Reset to initial state

setDefaultEscapeFilter (   $escapeFilter)
Parameters
mixed$escapeFilter
Returns
Zend_Filter_Interface
setDisableTranslator (   $flag)

Indicate whether or not translation should be disabled.

Parameters
bool$flag
Returns
Zend_Filter_Input
setOptions ( array  $options)
Parameters
array$options
Returns
Zend_Filter_Input
Exceptions
Zend_Filter_Exceptionif an unknown option is given
setPluginLoader ( Zend_Loader_PluginLoader_Interface  $loader,
  $type 
)

Set plugin loaders for use with decorators and elements.

Parameters
Zend_Loader_PluginLoader_Interface$loader
string$type'filter' or 'validate'
Returns
Zend_Filter_Input
Exceptions
Zend_Filter_Exceptionon invalid type
setTranslator (   $translator = null)

Set translation object.

Parameters
Zend_Translate | Zend_Translate_Adapter | null$translator
Returns
Zend_Filter_Input
translatorIsDisabled ( )

Is translation disabled?

Returns
bool

Member Data Documentation

$_data = array()
protected
$_defaultEscapeFilter = null
protected
$_defaults
protected
Initial value:
= array(
self::ALLOW_EMPTY => false,
self::BREAK_CHAIN => false,
self::ESCAPE_FILTER => 'HtmlEntities',
self::MISSING_MESSAGE => "Field '%field%' is required by rule '%rule%', but the field is missing",
self::NOT_EMPTY_MESSAGE => "You must give a non-empty value for field '%field%'",
self::PRESENCE => self::PRESENCE_OPTIONAL
)
$_filterRules = array()
protected
$_invalidErrors = array()
protected
$_invalidMessages = array()
protected
$_loaders = array()
protected
$_missingFields = array()
protected
$_processed = false
protected
$_translator
protected
$_translatorDisabled = false
protected
$_unknownFields = array()
protected
$_validatorRules = array()
protected
$_validFields = array()
protected
const ALLOW_EMPTY = 'allowEmpty'
const BREAK_CHAIN = 'breakChainOnFailure'
const DEFAULT_VALUE = 'default'
const ESCAPE_FILTER = 'escapeFilter'
const FIELDS = 'fields'
const FILTER = 'filter'
const FILTER_CHAIN = 'filterChain'
const FILTER_NAMESPACE = 'filterNamespace'
const INPUT_NAMESPACE = 'inputNamespace'
const MESSAGES = 'messages'
const MISSING_MESSAGE = 'missingMessage'
const NOT_EMPTY_MESSAGE = 'notEmptyMessage'
const PRESENCE = 'presence'
const PRESENCE_OPTIONAL = 'optional'
const PRESENCE_REQUIRED = 'required'
const RULE = 'rule'
const RULE_WILDCARD = '*'
const VALIDATE = 'validate'
const VALIDATOR = 'validator'
const VALIDATOR_CHAIN = 'validatorChain'
const VALIDATOR_CHAIN_COUNT = 'validatorChainCount'
const VALIDATOR_NAMESPACE = 'validatorNamespace'