\Cake\ValidationValidationSet

ValidationSet object. Holds all validation rules for a field and exposes methods to dynamically add or remove validation rules

Summary

Methods
Properties
Constants
isPresenceRequired()
requirePresence()
isEmptyAllowed()
allowEmpty()
rule()
rules()
add()
remove()
offsetExists()
offsetGet()
offsetSet()
offsetUnset()
getIterator()
count()
No public properties found
No constants found
No protected methods found
$_rules
$_validatePresent
$_allowEmpty
N/A
No private methods found
No private properties found
N/A

Properties

$_validatePresent

$_validatePresent : boolean|string|callable

Denotes whether the fieldname key must be present in data array

Type

boolean|string|callable

$_allowEmpty

$_allowEmpty : boolean|string|callable

Denotes if a field is allowed to be empty

Type

boolean|string|callable

Methods

isPresenceRequired()

isPresenceRequired(boolean|string|callable|null  $validatePresent = null) : boolean|string|callable

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 $validatePresent

Deprecated since 3.6.0 ValidationSet::isPresenceRequired() is deprecated as a setter Use ValidationSet::requirePresence() instead.

Returns

boolean|string|callable

requirePresence()

requirePresence(boolean|string|callable  $validatePresent) : $this

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

isEmptyAllowed()

isEmptyAllowed(boolean|string|callable|null  $allowEmpty = null) : boolean|string|callable

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 $allowEmpty

Deprecated since 3.6.0 ValidationSet::isEmptyAllowed() is deprecated as a setter. Use ValidationSet::allowEmpty() instead.

Returns

boolean|string|callable

allowEmpty()

allowEmpty(boolean|string|callable  $allowEmpty) : $this

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

rule()

rule(string  $name) : \Cake\Validation\ValidationRule|null

Gets a rule for a given name if exists

Parameters

string $name

The name under which the rule is set.

Returns

\Cake\Validation\ValidationRule|null

rules()

rules() : array<mixed,\Cake\Validation\ValidationRule>

Returns all rules for this validation set

Returns

array<mixed,\Cake\Validation\ValidationRule>

add()

add(string  $name, \Cake\Validation\ValidationRule|array  $rule) : $this

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

remove()

remove(string  $name) : $this

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

offsetExists()

offsetExists(string  $index) : boolean

Returns whether an index exists in the rule set

Parameters

string $index

name of the rule

Returns

boolean

offsetGet()

offsetGet(string  $index) : \Cake\Validation\ValidationRule

Returns a rule object by its index

Parameters

string $index

name of the rule

Returns

\Cake\Validation\ValidationRule

offsetSet()

offsetSet(string  $index, \Cake\Validation\ValidationRule|array  $rule) : void

Sets or replace a validation rule

Parameters

string $index

name of the rule

\Cake\Validation\ValidationRule|array $rule

Rule to add to $index

offsetUnset()

offsetUnset(string  $index) : void

Unsets a validation rule

Parameters

string $index

name of the rule

getIterator()

getIterator() : \ArrayIterator

Returns an iterator for each of the rules to be applied

Returns

\ArrayIterator

count()

count() : integer

Returns the number of rules in this set

Returns

integer