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: https://book.cakephp.org/2.0/en/data-validation.html
Copyright: Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
License: MIT License
Location: Cake/Model/Validator/CakeValidationSet.php
Properties summary
-
$_methods
protectedList of methods available for validationarray
-
$_rules
protected -
$_validationDomain
protectedI18n domain for validation messages.string
-
$field
publicHolds the fieldnamestring
-
$isStopped
publicWhether the validation is stoppedboolean
-
$ruleSet
publicHolds the original ruleSetarray
Method Summary
- __construct() publicConstructor
- _processValidationResponse() protectedFetches the correct error message for a failed validation
- _translateArgs() protectedApplies translations to validator arguments.
- count() publicReturns the number of rules in this set
- getIterator() publicReturns an iterator for each of the rules to be applied
- getRule() publicGets a rule for a given name if exists
- getRules() publicReturns all rules for this validation set
- offsetExists() publicReturns whether an index exists in the rule set
- offsetGet() publicReturns a rule object by its index
- offsetSet() publicSets or replace a validation rule.
- offsetUnset() publicUnsets a validation rule
- removeRule() publicRemoves a validation rule from the set
- reset() publicResets internal state for all validation rules in this set
- setMethods() publicSets the list of methods to use for validation
- setRule() publicSets a CakeValidationRule $rule with a $name
- setRules() publicSets the rules for a given field
- setValidationDomain() publicSets 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()source public
__construct( string $fieldName , array $ruleSet )
Constructor
Parameters
- string
$fieldName
- The fieldname.
- array
$ruleSet
- Rules set.
_processValidationResponse()source 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
string_translateArgs()source protected
_translateArgs( array $args )
Applies translations to validator arguments.
Parameters
- array
$args
- The args to translate
Returns
arrayTranslated args.
count()source public
count( )
Returns the number of rules in this set
Returns
integerImplementation of
Countable::count()
getIterator()source public
getIterator( )
Returns an iterator for each of the rules to be applied
Returns
ArrayIteratorImplementation of
IteratorAggregate::getIterator()
getRule()source public
getRule( string $name )
Gets a rule for a given name if exists
Parameters
- string
$name
- Field name.
Returns
CakeValidationRule
getRules()source public
getRules( )
Returns all rules for this validation set
Returns
CakeValidationRule[]
offsetExists()source public
offsetExists( string $index )
Returns whether an index exists in the rule set
Parameters
- string
$index
- name of the rule
Returns
booleanImplementation of
ArrayAccess::offsetExists()
offsetGet()source public
offsetGet( string $index )
Returns a rule object by its index
Parameters
- string
$index
- name of the rule
Returns
CakeValidationRule
Implementation of
ArrayAccess::offsetGet()
offsetSet()source public
offsetSet( string $index , CakeValidationRule|array $rule )
Sets or replace a validation rule.
This is a wrapper for ArrayAccess. Use setRule() directly for chainable access.
Parameters
- string
$index
- Name of the rule.
-
CakeValidationRule
|array$rule
- Rule to add to $index.
See
http://www.php.net/manual/en/arrayobject.offsetset.phpImplementation of
ArrayAccess::offsetSet()
offsetUnset()source public
offsetUnset( string $index )
Unsets a validation rule
Parameters
- string
$index
- name of the rule
Implementation of
ArrayAccess::offsetUnset()
removeRule()source 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
CakeValidationSet
setMethods()source public
setMethods( array $methods )
Sets the list of methods to use for validation
Parameters
- array
$methods
- $methods Methods list
setRule()source public
setRule( string $name , CakeValidationRule|array $rule )
Sets a CakeValidationRule $rule with a $name
Example:
$set ->setRule('required', array('rule' => 'notBlank', 'required' => true)) ->setRule('between', array('rule' => array('lengthBetween', 4, 10))
Parameters
- string
$name
- The name under which the rule should be set
-
CakeValidationRule
|array$rule
- The validation rule to be set
Returns
CakeValidationSet
setRules()source public
setRules( array $rules array() , boolean $mergeVars true )
Sets the rules for a given field
Example:
$set->setRules(array( 'required' => array('rule' => 'notBlank', 'required' => true), 'inRange' => array('rule' => array('between', 4, 10) ));
Parameters
- array
$rules
optional array() - The rules to be set
- boolean
$mergeVars
optional true - [optional] If true, merges vars instead of replace. Defaults to true.
Returns
CakeValidationSet
setValidationDomain()source public
setValidationDomain( string $validationDomain )
Sets the I18n domain for validation messages.
Parameters
- string
$validationDomain
- The validation domain to be used.
validate()source public
validate( array $data , boolean $isUpdate false )
Runs all validation rules in this set and returns a list of validation errors
Parameters
- array
$data
- Data array
- boolean
$isUpdate
optional false - Is record being updated or created
Returns
arraylist of validation errors for this field
Properties detail
© 2005–2017 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/2.10/class-CakeValidationSet.html