\Cake\ValidationValidationRule

ValidationRule object. Represents a validation method, error message and rules for applying such method to a field.

Summary

Methods
Properties
Constants
__construct()
isLast()
process()
get()
No public properties found
No constants found
_skip()
_addValidatorProps()
$_rule
$_on
$_last
$_message
$_provider
$_pass
N/A
No private methods found
No private properties found
N/A

Properties

$_rule

$_rule : string|callable

The method to be called for a given scope

Type

string|callable

$_on

$_on : string

The 'on' key

Type

string

$_last

$_last : boolean

The 'last' key

Type

boolean

$_message

$_message : string

The 'message' key

Type

string

$_provider

$_provider : string

Key under which the object or class where the method to be used for validation will be found

Type

string

$_pass

$_pass : array

Extra arguments to be passed to the validation method

Type

array

Methods

__construct()

__construct(array  $validator = array()) 

Constructor

Parameters

array $validator

[optional] The validator properties

isLast()

isLast() : boolean

Returns whether this rule should break validation process for associated field after it fails

Returns

boolean

process()

process(mixed  $value, array  $providers, array  $context = array()) : boolean|string

Dispatches the validation rule to the given validator method and returns a boolean indicating whether the rule passed or not. If a string is returned it is assumed that the rule failed and the error message was given as a result.

Parameters

mixed $value

The data to validate

array $providers

associative array with objects or class names that will be passed as the last argument for the validation method

array $context

A key value list of data that could be used as context during validation. Recognized keys are:

  • newRecord: (boolean) whether or not the data to be validated belongs to a new record
  • data: The full data that was passed to the validation process
  • field: The name of the field that is being processed

Throws

\InvalidArgumentException

when the supplied rule is not a valid callable for the configured scope

Returns

boolean|string

get()

get(string  $property) : mixed

Returns the value of a property by name

Parameters

string $property

The name of the property to retrieve.

Returns

mixed

_skip()

_skip(array  $context) : boolean

Checks if the validation rule should be skipped

Parameters

array $context

A key value list of data that could be used as context during validation. Recognized keys are:

  • newRecord: (boolean) whether or not the data to be validated belongs to a new record
  • data: The full data that was passed to the validation process
  • providers associative array with objects or class names that will be passed as the last argument for the validation method

Returns

boolean —

True if the ValidationRule should be skipped

_addValidatorProps()

_addValidatorProps(array  $validator = array()) : void

Sets the rule properties from the rule entry in validate

Parameters

array $validator

[optional]