Class ValidationSet
ValidationSet object. Holds all validation rules for a field and exposes methods to dynamically add or remove validation rules
- Cake\Validation\ValidationSet implements ArrayAccess, IteratorAggregate, Countable
Method Detail
addsource public
add( string $name , Cake\Validation\ValidationRule|array $rule )
Sets a ValidationRule $rule with a $name
Example:
$set ->add('notBlank', ['rule' => 'notBlank']) ->add('inRange', ['rule' => ['between', 4, 10])
Parameters
- string
$name - The name under which the rule should be set
-
Cake\Validation\ValidationRule|array$rule - The validation rule to be set
Returns
mixed$this
countsource public
count( )
Returns the number of rules in this set
Returns
integerint
Implementation of
Countable::count() getIteratorsource public
getIterator( )
Returns an iterator for each of the rules to be applied
Returns
ArrayIterator\ArrayIterator
Implementation of
IteratorAggregate::getIterator() isEmptyAllowedsource public
isEmptyAllowed( boolean|string|callable|null $allowEmpty null )
Sets whether a field value is allowed to be empty
If no argument is passed the currently set allowEmpty value will be returned.
Parameters
- boolean|string|callable|null
$allowEmptyoptional null - Valid values are true, false, 'create', 'update'
Returns
boolean|string|callablebool|string|callable
isPresenceRequiredsource public
isPresenceRequired( boolean|string|null $validatePresent null )
Sets whether a field is required to be present in data array.
If no argument is passed the currently set validatePresent value will be returned.
Parameters
- boolean|string|null
$validatePresentoptional null - Valid values are true, false, 'create', 'update'
Returns
boolean|stringbool|string
offsetExistssource public
offsetExists( string $index )
Returns whether an index exists in the rule set
Parameters
- string
$index - name of the rule
Returns
booleanbool
Implementation of
ArrayAccess::offsetExists() offsetGetsource public
offsetGet( string $index )
Returns a rule object by its index
Parameters
- string
$index - name of the rule
Returns
Cake\Validation\ValidationRule\Cake\Validation\ValidationRule
Implementation of
ArrayAccess::offsetGet() offsetSetsource public
offsetSet( string $index , Cake\Validation\ValidationRule|array $rule )
Sets or replace a validation rule
Parameters
- string
$index - name of the rule
-
Cake\Validation\ValidationRule|array$rule - Rule to add to $index
Implementation of
ArrayAccess::offsetSet() offsetUnsetsource public
offsetUnset( string $index )
Unsets a validation rule
Parameters
- string
$index - name of the rule
Implementation of
ArrayAccess::offsetUnset() removesource public
remove( string $name )
Removes a validation rule from the set
Example:
$set ->remove('notBlank') ->remove('inRange')
Parameters
- string
$name - The name under which the rule should be unset
Returns
mixed$this
rulesource public
rule( string $name )
Gets a rule for a given name if exists
Parameters
- string
$name - The name under which the rule is set.
Returns
Cake\Validation\ValidationRule\Cake\Validation\ValidationRule
Properties summary
© 2005–2016 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.
http://api.cakephp.org/3.1/class-Cake.Validation.ValidationSet.html