Fr3nch13/CakePHP Utilities

ValidationRule
in package

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

Table of Contents

Properties

$_last  : bool
The 'last' key
$_message  : string
The 'message' key
$_on  : callable|string
The 'on' key
$_pass  : array<string|int, mixed>
Extra arguments to be passed to the validation method
$_provider  : string
Key under which the object or class where the method to be used for validation will be found
$_rule  : callable|string
The method to be called for a given scope

Methods

__construct()  : mixed
Constructor
get()  : mixed
Returns the value of a property by name
isLast()  : bool
Returns whether this rule should break validation process for associated field after it fails
process()  : array<string|int, mixed>|string|bool
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.
_addValidatorProps()  : void
Sets the rule properties from the rule entry in validate
_skip()  : bool
Checks if the validation rule should be skipped

Properties

$_pass

Extra arguments to be passed to the validation method

protected array<string|int, mixed> $_pass = []

$_provider

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

protected string $_provider = 'default'

$_rule

The method to be called for a given scope

protected callable|string $_rule

Methods

__construct()

Constructor

public __construct([array<string, mixed> $validator = [] ]) : mixed
Parameters
$validator : array<string, mixed> = []

[optional] The validator properties

get()

Returns the value of a property by name

public get(string $property) : mixed
Parameters
$property : string

The name of the property to retrieve.

isLast()

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

public isLast() : bool
Return values
bool

process()

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.

public process(mixed $value, array<string, mixed> $providers[, array<string, mixed> $context = [] ]) : array<string|int, mixed>|string|bool
Parameters
$value : mixed

The data to validate

$providers : array<string, mixed>

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

$context : array<string, mixed> = []

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

  • newRecord: (boolean) whether 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
Tags
throws
InvalidArgumentException

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

Return values
array<string|int, mixed>|string|bool

_addValidatorProps()

Sets the rule properties from the rule entry in validate

protected _addValidatorProps([array<string, mixed> $validator = [] ]) : void
Parameters
$validator : array<string, mixed> = []

[optional]

_skip()

Checks if the validation rule should be skipped

protected _skip(array<string, mixed> $context) : bool
Parameters
$context : array<string, mixed>

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

  • newRecord: (boolean) whether 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
Return values
bool —

True if the ValidationRule should be skipped


        
On this page

Search results