Class CakeValidationSet
CakeValidationSet object. Holds all validation rules for a field and exposes methods to dynamically add or remove validation rules
- CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable
Link: http://book.cakephp.org/2.0/en/data-validation.html
Copyright: Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
License: License (http://www.opensource.org/licenses/mit-license.php)
Location: Cake/Model/Validator/CakeValidationSet.php
Properties summary
-
$_methods
protectedarray
List of methods available for validation -
$_rules
protectedarray
Holds the CakeValidationRule objects -
$_validationDomain
protectedstring
I18n domain for validation messages. -
$field
publicstring
Holds the fieldname -
$isStopped
publicboolean
Whether the validation is stopped -
$ruleSet
publicarray
Holds the original ruleSet
Method Summary
-
__construct() public
Constructor -
_processValidationResponse() protected
Fetches the correct error message for a failed validation -
_translateArgs() protected
Applies translations to validator arguments. -
count() public
Returns the number of rules in this set -
getIterator() public
Returns an iterator for each of the rules to be applied -
getRule() public
Gets a rule for a given name if exists -
getRules() public
Returns all rules for this validation set -
offsetExists() public
Returns wheter an index exists in the rule set -
offsetGet() public
Returns a rule object by its index -
offsetSet() public
Sets or replace a validation rule -
offsetUnset() public
Unsets a validation rule -
removeRule() public
Removes a validation rule from the set -
reset() public
Resets interal state for all validation rules in this set -
setMethods() public
Sets the list of methods to use for validation -
setRule() public
Sets a CakeValidationRule $rule with a $name -
setRules() public
Sets the rules for a given field -
setValidationDomain() public
Sets the I18n domain for validation messages. -
validate() public
Runs all validation rules in this set and returns a list of validation errors
Method Detail
__construct() public ¶
__construct( string $fieldName , array $ruleSet )
Constructor
Parameters
- string $fieldName
- The fieldname
- array $ruleSet
_processValidationResponse() protected ¶
_processValidationResponse( string $name , CakeValidationRule
$rule )
Fetches the correct error message for a failed validation
Parameters
- string $name
- the name of the rule as it was configured
-
CakeValidationRule
$rule - the object containing validation information
Returns
_translateArgs() protected ¶
_translateArgs( array $args )
Applies translations to validator arguments.
Parameters
- array $args
- The args to translate
Returns
Translated args.
count() public ¶
count( )
Returns the number of rules in this set
Returns
Implementation of
Countable::count()
getIterator() public ¶
getIterator( )
Returns an iterator for each of the rules to be applied
Returns
Implementation of
IteratorAggregate::getIterator()
offsetExists() public ¶
offsetExists( string $index )
Returns wheter an index exists in the rule set
Parameters
- string $index
- name of the rule
Returns
Implementation of
ArrayAccess::offsetExists()
offsetGet() public ¶
offsetGet( string $index )
Returns a rule object by its index
Parameters
- string $index
- name of the rule
Returns
Implementation of
ArrayAccess::offsetGet()
offsetSet() public ¶
offsetSet( string $index , CakeValidationRule
|array $rule )
Sets or replace a validation rule
Parameters
- string $index
- name of the rule
-
CakeValidationRule
|array $rule - to add to $index
Implementation of
ArrayAccess::offsetSet()
offsetUnset() public ¶
offsetUnset( string $index )
Unsets a validation rule
Parameters
- string $index
- name of the rule
Implementation of
ArrayAccess::offsetUnset()
removeRule() public ¶
removeRule( string $name )
Removes a validation rule from the set
Example:
{{{ $set ->removeRule('required') ->removeRule('inRange') }}}
Parameters
- string $name
- The name under which the rule should be unset
Returns
setRule() public ¶
setRule( string $name , CakeValidationRule
|array $rule )
Sets a CakeValidationRule $rule with a $name
Example:
{{{ $set ->setRule('required', array('rule' => 'notEmpty', 'required' => true)) ->setRule('inRange', array('rule' => array('between', 4, 10)) }}}
Parameters
- string $name
- The name under which the rule should be set
-
CakeValidationRule
|array $rule - The validation rule to be set
Returns
setRules() public ¶
setRules( array $rules = array() , bolean $mergeVars = true )
Sets the rules for a given field
Example:
{{{ $set->setRules(array( 'required' => array('rule' => 'notEmpty', 'required' => true), 'inRange' => array('rule' => array('between', 4, 10) )); }}}
Parameters
- array $rules optional array()
- The rules to be set
- bolean $mergeVars optional true
- [optional] If true, merges vars instead of replace. Defaults to true.
Returns
setValidationDomain() public ¶
setValidationDomain( string $validationDomain )
Sets the I18n domain for validation messages.
Parameters
- string $validationDomain
- The validation domain to be used.
validate() public ¶
validate( $data , $isUpdate = false )
Runs all validation rules in this set and returns a list of validation errors
Returns
list of validation errors for this field