On this page
Class ValidationRule
ValidationRule object. Represents a validation method, error message and rules for applying such method to a field.
Property Summary
-
$_last protected
bool
The 'last' key
-
$_message protected
string
The 'message' key
-
$_on protected
callable|string
The 'on' key
-
$_pass protected
array
Extra arguments to be passed to the validation method
-
$_provider protected
string
Key under which the object or class where the method to be used for validation will be found
-
$_rule protected
callable|string
The method to be called for a given scope
Method Summary
__construct() public
Constructor
_addValidatorProps() protected
Sets the rule properties from the rule entry in validate
_skip() protected
Checks if the validation rule should be skipped
get() public
Returns the value of a property by name
isLast() public
Returns whether this rule should break validation process for associated field after it fails
process() public
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.
Method Detail
__construct() public
__construct(array<string, mixed> $validator = [])
Constructor
Parameters
array<string, mixed>
$validator optional-
[optional] The validator properties
_addValidatorProps() protected
_addValidatorProps(array<string, mixed> $validator = []): void
Sets the rule properties from the rule entry in validate
Parameters
array<string, mixed>
$validator optional-
[optional]
Returns
void
_skip() protected
_skip(array<string, mixed> $context): bool
Checks if the validation rule should be skipped
Parameters
array<string, mixed>
$context-
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
Returns
bool
get() public
get(string $property): mixed
Returns the value of a property by name
Parameters
string
$property-
The name of the property to retrieve.
Returns
mixed
isLast() public
isLast(): bool
Returns whether this rule should break validation process for associated field after it fails
Returns
bool
process() public
process(mixed $value, array<string, mixed> $providers, array<string, mixed> $context = []): array|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.
Parameters
mixed
$value-
The data to validate
array<string, mixed>
$providers-
Associative array with objects or class names that will be passed as the last argument for the validation method
array<string, mixed>
$context optional-
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
Returns
array|string|bool
Throws
InvalidArgumentException
when the supplied rule is not a valid callable for the configured scope
Property Detail
$_last protected
The 'last' key
Type
bool
$_message protected
The 'message' key
Type
string
$_on protected
The 'on' key
Type
callable|string
$_pass protected
Extra arguments to be passed to the validation method
Type
array
$_provider protected
Key under which the object or class where the method to be used for validation will be found
Type
string
$_rule protected
The method to be called for a given scope
Type
callable|string
© 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/4.4/class-Cake.Validation.ValidationRule.html