Class CakeValidationRule

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

Package: Cake\Model\Validator
Link: https://book.cakephp.org/2.0/en/data-validation.html
Copyright: Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
License: MIT License
Location: Cake/Model/Validator/CakeValidationRule.php

Properties summary

  • $_passedOptions protected
    array
    Holds passed in options
  • $_recordExists protected
    boolean
    Holds whether the record being validated exists in datasource or not
  • $_rule protected
    mixed
    Validation method
  • $_ruleParams protected
    array
    Validation method arguments
  • $_valid protected
    mixed
    Whether the field passed this validation rule
  • $allowEmpty public
    boolean
    The 'allowEmpty' key
  • $last public
    boolean
    The 'last' key
  • $message public
    string
    The 'message' key
  • $on public
    string
    The 'on' key
  • $required public
    mixed
    The 'required' key
  • $rule public
    mixed
    The 'rule' key

Method Summary

  • __construct() public
    Constructor
  • Sets the rule properties from the rule entry in validate
  • Gets an array with the rule properties
  • _parseRule() protected
    Parses the rule and sets the rule and ruleParams
  • checkEmpty() public
    Checks if the allowEmpty key applies
  • Checks whether the field failed the field should be present validation
  • getOptions() public
    Returns passed options for this rule
  • Gets the validation error message
  • Returns whether the field can be left blank according to this rule
  • isLast() public

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

  • isRequired() public
    Checks if the field is required according to the required property
  • isUpdate() public

    Sets the recordExists configuration value for this rule, ir refers to whether the model record it is validating exists exists in the collection or not (create or update operation)

  • isValid() public
    Checks if the rule is valid
  • process() public
    Dispatches the validation rule to the given validator method
  • reset() public

    Resets internal state for this rule, by default it will become valid and it will set isUpdate() to false

  • skip() public
    Checks if the validation rule should be skipped

Method Detail

__construct()source public

__construct( array $validator array() )

Constructor

Parameters

array $validator optional array()
[optional] The validator properties

_addValidatorProps()source protected

_addValidatorProps( array $validator array() )

Sets the rule properties from the rule entry in validate

Parameters

array $validator optional array()
[optional]

_getPropertiesArray()source protected

_getPropertiesArray( )

Gets an array with the rule properties

Returns

array

_parseRule()source protected

_parseRule( string $field , array $data )

Parses the rule and sets the rule and ruleParams

Parameters

string $field
Field name
array $data
$data Data array

checkEmpty()source public

checkEmpty( string $field , array $data )

Checks if the allowEmpty key applies

Parameters

string $field
Field name
array $data
$data data to check rule against

Returns

boolean

checkRequired()source public

checkRequired( string $field , array $data )

Checks whether the field failed the field should be present validation

Parameters

string $field
Field name
array $data
$data Data to check rule against

Returns

boolean

getOptions()source public

getOptions( string|integer $key )

Returns passed options for this rule

Parameters

string|integer $key
Array index

Returns

array|null

getValidationResult()source public

getValidationResult( )

Gets the validation error message

Returns

string

isEmptyAllowed()source public

isEmptyAllowed( )

Returns whether the field can be left blank according to this rule

Returns

boolean

isLast()source public

isLast( )

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

Returns

boolean

isRequired()source public

isRequired( )

Checks if the field is required according to the required property

Returns

boolean

isUpdate()source public

isUpdate( boolean $exists null )

Sets the recordExists configuration value for this rule, ir refers to whether the model record it is validating exists exists in the collection or not (create or update operation)

If called with no parameters it will return whether this rule is configured for update operations or not.

Parameters

boolean $exists optional null
Boolean to indicate if records exists

Returns

boolean

isValid()source public

isValid( )

Checks if the rule is valid

Returns

boolean

process()source public

process( string $field , array $data , array $methods )

Dispatches the validation rule to the given validator method

Parameters

string $field
Field name
array $data
$data Data array
array $methods
$methods Methods list

Returns

boolean
True if the rule could be dispatched, false otherwise

reset()source public

reset( )

Resets internal state for this rule, by default it will become valid and it will set isUpdate() to false

skip()source public

skip( )

Checks if the validation rule should be skipped

Returns

boolean
True if the ValidationRule can be skipped

Properties detail

$_passedOptionssource

protected array

Holds passed in options

array()

$_recordExistssource

protected boolean

Holds whether the record being validated exists in datasource or not

false

$_rulesource

protected mixed

Validation method

null

$_ruleParamssource

protected array

Validation method arguments

array()

$_validsource

protected mixed

Whether the field passed this validation rule

true

$allowEmptysource

public boolean

The 'allowEmpty' key

null

$lastsource

public boolean

The 'last' key

true

$messagesource

public string

The 'message' key

null

$onsource

public string

The 'on' key

null

$requiredsource

public mixed

The 'required' key

null

$rulesource

public mixed

The 'rule' key

'blank'

© 2005–2017 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/2.10/class-CakeValidationRule.html