Class ValidationRule
ValidationRule object. Represents a validation method, error message and rules for applying such method to a field.
Property Summary
- 
        $_last protectedboolThe 'last' key 
- 
        $_message protectedstringThe 'message' key 
- 
        $_on protectedstring|callableThe 'on' key 
- 
        $_pass protectedarrayExtra arguments to be passed to the validation method 
- 
        $_provider protectedstringKey under which the object or class where the method to be used for validation will be found 
- 
        $_rule protectedstring|callableThe method to be called for a given scope 
Method Summary
- 
          __construct() publicConstructor 
- 
          _addValidatorProps() protectedSets the rule properties from the rule entry in validate 
- 
          _skip() protectedChecks if the validation rule should be skipped 
- 
          get() publicReturns the value of a property by name 
- 
          isLast() publicReturns whether this rule should break validation process for associated field after it fails 
- 
          process() publicDispatches 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 $validator = [])Constructor
Parameters
- 
                array$validator optional
- [optional] The validator properties 
_addValidatorProps() ¶ protected
_addValidatorProps(array $validator = []): voidSets the rule properties from the rule entry in validate
Parameters
- 
                array$validator optional
- [optional] 
Returns
void_skip() ¶ protected
_skip(array $context): boolChecks 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
boolTrue if the ValidationRule should be skipped
get() ¶ public
get(string $property): mixedReturns the value of a property by name
Parameters
- 
                string$property
- The name of the property to retrieve. 
Returns
mixedisLast() ¶ public
isLast(): boolReturns whether this rule should break validation process for associated field after it fails
Returns
boolprocess() ¶ public
process(mixed $value, array $providers, array $context = []): bool|string|arrayDispatches 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 optional
- 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
 
Returns
bool|string|arrayThrows
InvalidArgumentExceptionwhen the supplied rule is not a valid callable for the configured scope
Property Detail
$_provider ¶ protected
Key under which the object or class where the method to be used for validation will be found
Type
string