On this page
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
Properties summary
- 
    $_allowEmptyprotectedDenotes if a field is allowed to be emptyboolean|string|callable
- 
    Holds the ValidationRule objects$_rulesprotected
- 
    $_validatePresentprotectedDenotes whether the fieldname key must be present in data arrayboolean|string|callable
Method Summary
- 
    add() publicSets a ValidationRule $rule with a $name
- 
    allowEmpty() publicSets whether a field value is allowed to be empty.
- 
    count() publicReturns the number of rules in this set
- 
    getIterator() publicReturns an iterator for each of the rules to be applied
- 
    isEmptyAllowed() publicSets whether a field value is allowed to be empty.
- 
    isPresenceRequired() publicSets whether a field is required to be present in data array.
- 
    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
- 
    remove() publicRemoves a validation rule from the set
- 
    requirePresence() publicSets whether a field is required to be present in data array.
- 
    rule() publicGets a rule for a given name if exists
- 
    rules() publicReturns all rules for this validation set
Method Detail
add()source 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
$this
allowEmpty()source public
allowEmpty( boolean|string|callable $allowEmpty )Sets whether a field value is allowed to be empty.
Parameters
- 
     boolean|string|callable $allowEmpty
- 
     Valid values are true, false, 'create', 'update' or a callable. 
Returns
$this
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()
  isEmptyAllowed()source 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
- 
     Deprecated since 3.6.0 ValidationSet::isEmptyAllowed() is deprecated as a setter. Use ValidationSet::allowEmpty() instead. 
Returns
boolean|string|callableisPresenceRequired()source public
isPresenceRequired( boolean|string|callable|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|callable|null $validatePresentoptional null
- 
     Deprecated since 3.6.0 ValidationSet::isPresenceRequired() is deprecated as a setter Use ValidationSet::requirePresence() instead. 
Returns
boolean|string|callableoffsetExists()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
Cake\Validation\ValidationRuleImplementation of
ArrayAccess::offsetGet()
  offsetSet()source 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()
  offsetUnset()source public
offsetUnset( string $index )Unsets a validation rule
Parameters
- 
     string $index
- name of the rule
Implementation of
ArrayAccess::offsetUnset()
  remove()source 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
$this
requirePresence()source public
requirePresence( boolean|string|callable $validatePresent )Sets whether a field is required to be present in data array.
Parameters
- 
     boolean|string|callable $validatePresent
- Valid values are true, false, 'create', 'update' or a callable.
Returns
$this
rule()source 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|nullrules()source public
rules( )Returns all rules for this validation set
Returns
Cake\Validation\ValidationRule[]Properties detail
$_allowEmptysource
protected boolean|string|callable
Denotes if a field is allowed to be empty
false$_validatePresentsource
protected boolean|string|callable
Denotes whether the fieldname key must be present in data array
false© 2005–present 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/3.8/class-Cake.Validation.ValidationSet.html